By: Amit Yadav

**Prerequisite:**

- Familiar with if-else statement
- Familiar with for loop
- Familiar with C-Operator

*Factorial of a number:*

- fact(5) = 5*4*3*2*1
- fact(n) = n*(n-1)*(n-2)*(n-3)…………(n)

**Program**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include<stdio.h> int main() { unsigned long int numb,i; unsigned long int fact=1; printf("\n Program to find factorial of any number"); printf("\nPlease enter any Number: "); scanf("%ld",&numb); for(i=numb;i>0;i--) { if(numb==0) { fact=1; break; } fact=fact*i; } printf("\nfactorial of %ld is= %ld",numb,fact); return 0; } |

1 2 3 4 5 |
Output: Program to find factorial of any number Please enter any Number: 5 factorial of 5 is= 120 |