**Introduction**

This is a tutorial of c++ program to calculate the factorial of the number using while loop. The program calculates the factorial by multiplying the factorial by increased number. The program is not extendable. Go enjoy the program. Lets begin….

**What’s a factorial?**

You may have studied factorial in your maths book. The factorial is usually denoted by n! .i.e 5! is factorial of 5. The factorial is calculated as:- 5! =1x2x3x4x5.

**Program to calculate the factorial of number using while loop**

```
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int no,fact=1,i;
//Input the two numbers save it
cout<<"Enter the no."<<endl;
cin>>no;
//Calculate the factorial using loop
i=1;
while(i<=no)
{
fact=fact*i;
i++;
}
//show the output 'fact'
cout<<"The factorial is "<<fact;
//get character
getch();
}
```

**Output**

Enter the no.

5

The factorial is 120

**How does it work**

- You enter the number.
- The factorial is calculated using while loop
- The factorial is printed.

**Extending it**

The program cannot be extended.

**Explanation.**

- Include ‘iostream.h’ and ‘conio.h’ files.
- Add void main.
- Start program by first clearing the screen.
- Declare the variables as int (name them as you want.)
- Add the cout and cin of number.
- Add the while loop to calculate the factorial
- Print the factorial of the number.

**At the end**

You learnt creating the c++ program of Calculating the factorial of the given number. So now enjoy the program.

Please comment on the post and share it.

And like it if you liked.