C++ Program to find factorial of a Number

What is Factorial of a number?

Factorial of a number ‘n’┬áis the product of all positive integers less than or equal to n, denoted by ‘n!’. For example find factorial of 5.

5! = 5 x 4 x 3 x 2 x 1 = 120

Now let’s see the program to find factorial of a number in C++

PROGRAM:

#include<iostream>
using namespace std;
int main()
{
    int num,factorial=1;
    cout<<" Enter Number To Find Its Factorial: ";
    cin>>num;
    for(int a=1;a<=num;a++)
    {
        factorial=factorial*a;
    }
    cout<<"Factorial of Given Number is ="<<factorial<<endl;
    return 0;
}

Sample Output:

Enter Number To Find Its Factorial: 5
Factorial of Given Number is = 120

Leave a Reply