Answer to Question #28273 in C++ for sushmita

Question #28273
write a program to find the factorial of a number
1
Expert's answer
2013-04-16T11:59:36-0400
#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";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS