Hi Today we make a Program How To Find the Factorial of a Number using while loop in C++ .Now We Start it.
What is Factorial of a Number:
The factorial of a Number n, denoted by n!, is the product of all positive integers less than or equal to n.
Find the Factorial of a Number using while loop in C++
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int x;
cout<<"Enter the value for which you want the factorial:";
cin>>x;
int f=1;
int n=1;
while(n<=x)
{
f=f*n;
n=n+1;
}
cout<<"This is the required value:"<<f<<endl;
getch();
}
Output of Program
Enter a positive integer: 4 Factorial of 4 = 24