In this program, you will learn how to find factorial of a number.
The factorial of a number is the product of all the integers from 1 to that number.
For example, the factorial of 4 (denoted as 4!) is 1*2*3*4 = 24.
Factorial is not defined for negative numbers and the factorial of zero is one, 0! = 1 .
#include <iostream>
using namespace std;
int main()
{
int no, fact = 1;
cout<<"Enter the number: ";
cin>> no;
while(no > 0)
{
fact = fact * no;
no--;
}
cout<<"Factorial of given number is: " << fact;
return 0;
}
Enter the number: 4
Factorial of given number is: 24
Enter the number: 7
Factorial of given number is: 5040