Welcome to Code Helper

Factorial of a Number


The factorial of a positive integer n is equal to 1*2*3*...n.


➣ Source Code

 
		   
#include <iostream>
using namespace std;

int main()
{
    unsigned int n;
    unsigned long long factorial = 1;

    cout << "Enter a positive integer: ";
    cin >> n;

    for(int i = 1; i <=n; ++i)
    {
        factorial *= i;
    }

    cout << "Factorial of " << n << " = " << factorial;    
    return 0;
}
	
		 
		

➣ Output

 
Enter a positive integer: 5
Factorial of 5 = 120
		
	
 BACK 
Made with ❤