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 write a program to implement the same in C++
Write a program to find factorial of a Number in C++:
#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
