Answer to Question #16053 in C++ for Richard
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
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment