C++ program to find the factorial of a given number
codeaft.cpp
#include <iostream>
using namespace std;
int main()
{
    long i, 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";
    return 0;
}
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:~$
Comments and Reactions
What Next?
C++ Strings