#include <iostream>
// Function definition for factorial calculation
long long factorial(int n) {
// Base case: if n is 0 or 1, return 1
if (n <= 1) {
return 1;
}
// Recursive step: call factorial function again with a smaller problem (n - 1)
else {
return n * factorial(n - 1);
}
}
int main() {
int number = 5;
// Call the factorial function
std::cout << "Factorial of " << number << " is: " << factorial(number) << std::endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: