Westonci.ca offers quick and accurate answers to your questions. Join our community and get the insights you need today. Discover detailed solutions to your questions from a wide network of experts on our comprehensive Q&A platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

write a c++ program to calculate the factorial of a number

Sagot :

tonb

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