C++ Program to Find Factorial of n using While Loop

C++ Program to Find Factorial of n using While Loop

Write C++ Program to Find Factorial of n using While Loop

// CPP Program to Find Factorial of n using While Loop

#include <iostream>

using namespace std;

int main()
{

	int n, i, fact = 1;

	cout << "Enter the number :--> ";
	cin >> n;

	i = 1;

	while(i <= n)
	{
        fact = fact * i;
        i++;
	}

	cout << "The factorial of " << n << " is " << fact;

	return 0;
}

Output:

Enter the number :--> 6
The factorial of 6 is 720