Answer to Question #83684 in C++ for alaa albahri

Question #83684
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
1
Expert's answer
2018-12-13T08:31:10-0500
#include <iostream>
using namespace std;

int main()
{
    unsigned int n;
    unsigned long long factorial = 1;

    cout << "Enter a positive integer: ";
    cin >> n;

    for(int i = 1; i <=n; ++i)
    {
        factorial *= i;
    }

    cout << "Factorial of " << n << " is " << factorial;    
    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