Professional Documents
Culture Documents
Problem Statement:
To write a program in C to calculate the factorial of a given
number,where Nis the input given by the user.
Algorithm:
Variable listing:
Name Data type Function
C Int Assigned 1 so the value
is not less than N.
N Int it is the input given by
the user.
Fact Int A factorial is a product
of all the numbers
starting from 1.
Step 6: return 0.
Step 7: stop.
Source Code :
#include<stdio.h>
int main()
{
int c,n,fact=1;
printf("enter a number to calculate its factorial\n");
scanf("%d",&n);
for(c=1;c<=n;c++)
fact=fact*c;
printf("factorial of%d=%d\n",n,fact);
return 0;
}
<OUTPUT>
Set 1:
Enter a number to calculate its factorial
5
Factorial of 5=120
Set 2:
Enter a number to calculate its factorial
6
Factorial of 6=720
Set 3:
Enter a number to calculate its factorial
10
Factorial of 10=3628800
-:-------------------:-