While Loop User Input in C

User Input in While Loop in C programming is a control flow that reads from user input a sequence and stops reading from user input until the condition is met.

While Loop User Enter value Printing in Descending Order

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter value: ");
scanf("%d", &n); //user enter value saving in 'n'.
while(n != 0) //checking condition.
{
printf("%d\n", n--); //printing 'n' value and Subtracting 1.
}
getch();
}
Output
Enter value: 8
8
7
6
5
4
3
2
1

Program While Loop using If Statement

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
if(a > 4 && a < 8) //if 'a' value greater then 4 OR less then 8 then
{
printf("%d\n", a); //print 'a' value.
}
a++; //adding 1 to 'a' value.
}
getch();
}
Output
5
6
7

Program While Loop Password program

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 0;
while(a != 12345) //loop stops when 'a' value Equal to 12345.
{
printf("Please Enter Password: ");
scanf("%d", &a); //user Enter value storing in 'a'.
}
printf("Password Correct!");
getch();
}
Output
Please Enter Password: 123
Please Enter Password: 664356
Please Enter Password: 12345
Password Correct!