This tutorial explains program example to find a factorial of a number using for loop as well as while loop.
#include <stdio.h>
int main()
{
int i,n,fact=1;
printf("\n Enter value of n ");
scanf("%d",&n);
//i=1;
//while(i<=n)
for(i=1;i<=n;i++)
{
fact=fact*i;
//i++:
}
printf("\n Factorial is %d ",fact);
return 0;
}
Comments
Post a Comment