/*C program to demonstrate the working of while loop*/
#include <stdio.h>
#include <conio.h>
void main()
{
int n,factorial;
printf("Enter a number.\n");
scanf("%d",&n);
factorial=1;
while (n>0) /* while loop continues util test condition number>0 is true */
{
factorial=factorial*n;
--n; /*or n--*/
}
printf("Factorial=%d",factorial);
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int n,factorial;
printf("Enter a number.\n");
scanf("%d",&n);
factorial=1;
while (n>0) /* while loop continues util test condition number>0 is true */
{
factorial=factorial*n;
--n; /*or n--*/
}
printf("Factorial=%d",factorial);
getch();
}