Answer to Question #16053 in C++ for Richard

Question #16053
how do i write a c++ program that will input a number and output its factorial using the while loop or for loop. Thanks
1
Expert's answer
2012-10-24T11:33:48-0400

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int j;&
cout << "Enter any number" << endl;
cin >> j;
long nFact = 1L;
if (j < 0)
& return 0L;
else if (j < 2)
& return 1L;
for (long i = j; i > 1; --i)
& nFact *= i;
cout << "Factorial of " << j << " is " << nFact;
getch();
return 0;
}

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