#include <iostream>
using namespace std;
int main() {
cout << "Enter a positive number: ";
int number;
cin >> number;
if (number < 0)
cout << "Error! Number is not positive";
else {
int factorial = 1;
for (int i = 1; i<=number; i++)
factorial = factorial * i; // factorial *= i
cout << "The factorial of " << number << ": " << factorial;
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter