Answer to Question #345468 in C++ for Monty

Question #345468

write an inline function, factorial (int x) which returns the factorial of value x. Test the function by reading values from the keyboard


1
Expert's answer
2022-05-27T09:39:28-0400
#include <iostream>
using namespace std;

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

    cout << "Enter  integer N: ";
    cin >> n;

    if (n < 0)
        cout << "Error! Factorial of a negative number doesn't exist";
        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
APPROVED BY CLIENTS