Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements
  5. Looping statements
  6. While loop

While loop

Syntax

while(expression)
{
statement
}

Flowchart

Example

Factorial of a number

//Factorial of a number
#include<stdio.h>
int main()
{
	int num, lc=1, fact=1;
printf("Enter a number\t");
scanf("%d",&num);
while(lc<=num)
{
	fact = fact *lc;
	lc=lc+1;
}
printf("Factorial is %d",fact);
return 0;
}

Output

Enter a number  5
Factorial is 120

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments