Question #28273

write a program to find the factorial of a number

Expert's answer

#include <iostream>

int main()

{

//Enter number

std::cout << "Enter number n to find factorial:\n";

unsigned n = 0;

std::cin >> n ;

long long fact = 1;

//calculate factorial n!=1*2*3*...*n:

for( unsigned i =1; i <= n; ++i )

{

fact=fact*i;

}

std::cout << n << "!=" << fact <<"\n";

}

int main()

{

//Enter number

std::cout << "Enter number n to find factorial:\n";

unsigned n = 0;

std::cin >> n ;

long long fact = 1;

//calculate factorial n!=1*2*3*...*n:

for( unsigned i =1; i <= n; ++i )

{

fact=fact*i;

}

std::cout << n << "!=" << fact <<"\n";

}

## Comments

## Leave a comment