Answer to Question #317593 in C++ for Zaki

Question #317593

write a program that enter number from user and display its factorial.e.g. factorial of 5 is 1×2×3×4×5=120. Where N<=10

1
Expert's answer
2022-03-24T11:26:53-0400
#include <iostream>
using namespace std;

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

    cout << "Enter  integer N (1-10): ";
    cin >> n;

    if (n < 0)
        cout << "Error! Factorial of a negative number doesn't exist";
    else if (n > 10)  
          cout << "Error! N must be <=10";
    else {
        for(int i = 1; i <= n; ++i) {
            factorial *= i;
        }
        cout << "Factorial of " << n << " = " << 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
New on Blog