Or in c++
#include <iostream>
// Function to calculate the factorial of a number
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
// Main function
int main() {
// Input: Get a number from the user
int num;
std::cout << "Enter a number: ";
std::cin >> num;
// Call the factorial function and display the result
int result = factorial(num);
std::cout << "Factorial of " << num << " is: " << result << std::endl;
return 0;
}