Answer to Question #100844 in C++ for Q3

Question #100844
Write a program that will display the result of n! using a loop. For example,if the user enters 5 for
n, the program should display “factorial of is 120”. solve with while
1
Expert's answer
2020-01-02T10:45:10-0500

#include <iostream>

using namespace std;

int main() {

int n, result = 1, i = 1;

cout<<"Enter n!\n";

cin>>n;

while(i <= n){

result *= i;

i++;

}

cout<<"factorial of "<<n<<" is "<<result<<endl;

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
New on Blog
APPROVED BY CLIENTS