write an inline function, factorial (int x) which returns the factorial of value x. Test the function by reading values from the keyboard
#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;
}
Comments
Leave a comment