//Factorial of a number using 'While-Loop'
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact=1;
printf("Enter any number:");
scanf("%d",&n);
while(n!=0)
{
fact=fact*n;
n--;
}
printf("Factorial of a number is:%d",fact);
getch();
}
Enter any number:5
Factorial of a number is:120
1. First the computer reads the number to find the factorial of the number from the user.
2. Then using while loop the value of ‘i’ is multiplied with the value of ‘f’.
3. The loop continues till the value of ‘i’ is less than or equal to ‘n’.
4. Finally the factorial value of the given number is printed.