#include <iostream>
int main() {
int n;
long long factorial = 1;
// Prompt user for input
std::cout << "Enter a positive integer: ";
std::cin >> n;
// Check for negative input
if (n < 0) {
std::cout << "Factorial is not defined for negative numbers." << std::endl;
} else {
// Calculate factorial
for (int i = 1; i <= n; ++i) {
factorial *= i;
}
std::cout << "Factorial of " << n << " = " << factorial << std::endl;
}
return 0;
}
factorial = i;
was incorrect. It should be factorial *= i;
to accumulate the product.n & Lt; 0
appeared to be a malformed HTML entity — it should be n < 0
.