C++ program to find the factorial of a given number
codeaft.cpp
#include<iostream>usingnamespacestd;intmain(){longi,n,fact=1;cout<<"———————————————————————————————————————————";cout<<"\nProgram to find the factorial of a given number ";cout<<"\n———————————————————————————————————————————";cout<<"\nEnter the number ";cin>>n;if(n>20||n<0){cout<<"\nOOP's can't find "<<n<<"!";}else{for(i=1;i<=n;i++){fact=fact*i;}cout<<"\nFactorial of "<<n<<" = "<<fact;}cout<<"\n———————————————————————————————————————————\n";return0;}
Output
codeaft@codeaft:~$ g++ codeaft.cpp codeaft@codeaft:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 25
OOP's can't find 25!
———————————————————————————————————————————
codeaft@codeaft:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 15
Factorial of 15 = 1307674368000
———————————————————————————————————————————
codeaft@codeaft:~$
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.