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++.
#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 << "Factorial is:" << f;
return 0;
}
Output:
Enter a number:4
Factorial is:24