C++ program to find the factorial of a given number
kw.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
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 25
OOP's can't find 25!
———————————————————————————————————————————
kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 15
Factorial of 15 = 1307674368000
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.