C++ Program to find factorial of a number


In this program, You will learn how to find factorial of a number in C++.


3! = 1 * 2 * 3

4! = 1 * 2 * 3 * 4

5! = 1 * 2 * 3 * 4 * 5


Example: How to find factorial of a number in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    long int num, i, f = 1;

    cout << "Enter a number :";
    cin>>num;

    for (i = 1; i <= num; i++) {
        f = f * i;
    }
    cout << "\nThe factorial is :" << f;

    return 0;
}

Output:

Enter a number :4
The factorial is :24