Get insightful responses to your questions quickly and easily on IDNLearn.com. Get step-by-step guidance for all your technical questions from our knowledgeable community members.
Answer:
#include <iostream>
int factorial(int n) {
return (n > 1) ? n*factorial(n-1) : 1;
}
int main() {
std::cout << factorial(5);
}
Explanation:
Above is an approach using recursion.
It will output 120, which is 5! = 5*4*3*2*1