STEPS
1. Initialize variable fact with 1.
fact = 1;
2. Multiply fact with the given number.
fact = fact * num;
3. Decrement number by 1.
num-- ;
4. Repeat steps 2-3 till num>0.
PROGRAM
//Program to calculate factorial of a given number
#include <iostream>
using namespace std;
int main()
{
int i,n;
long fact=1;
cout<<"ENTER THE NUMBER: ";
cin>>n;
while(n!=0)
{
fact=fact*n;
n--;
}
cout<<"FACTORIAL IS: "<<fact;
return 0;
}
OUTPUT
1. Initialize variable fact with 1.
fact = 1;
2. Multiply fact with the given number.
fact = fact * num;
3. Decrement number by 1.
num-- ;
4. Repeat steps 2-3 till num>0.
PROGRAM
//Program to calculate factorial of a given number
#include <iostream>
using namespace std;
int main()
{
int i,n;
long fact=1;
cout<<"ENTER THE NUMBER: ";
cin>>n;
while(n!=0)
{
fact=fact*n;
n--;
}
cout<<"FACTORIAL IS: "<<fact;
return 0;
}
OUTPUT