Untitled
unknown
plain_text
3 years ago
410 B
9
Indexable
#include <iostream>
// Inline recursive function to calculate the factorial of a number
inline int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
}
else {
return n * factorial(n - 1);
}
}
int main() {
int num;
std::cout << "Enter a number: ";
std::cin >> num;
std::cout << "Factorial of " << num << " is " << factorial(num) << std::endl;
return 0;
}
Editor is loading...