Prerequisite:
Factorial of a number:
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 |