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
//clear the screen.
//declare variable type int
//Input the two numbers save it
cout<<“Enter the no.”<<endl;
//Calculate the factorial using loop
//show the output ‘fact’
cout<<“The factorial is “<<fact;
Enter the no.
The factorial is 120
How does it work
- You enter the number.
- The factorial is calculated using while loop
- The factorial is printed.
The program cannot be extended.
- 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.