1//Factorial of a given number
2#include <stdio.h>
3
4//This function returns factorial of the number passed to it
5long int factorialOf(int number){
6 long int factorial = 1;
7 while(number){
8 factorial*=number;
9 number-=1;
10 }
11 return factorial;
12}
13
14int main(void) {
15 int n;
16 printf("Find factorial of \n");
17 scanf("%d",&n);
18 printf("\nThe factorial of %d is %ld",n,factorialOf(n));
19 return 0;
20}
1#include <stdio.h>
2
3int main()
4{
5 int i, num, fact = 1;
6
7 printf("Enter Number to Calculate Factorial: \n");
8 scanf("%d", &num);
9
10 for (i = 1; i <= num; i++){
11 fact = fact * i;
12 }
13
14 printf("Factorial of %d = %d\n", num, fact);
15
16 return 0;
17}