abongasalifubashiru abongasalifubashiru
  • 01-09-2021
  • Computers and Technology
contestada

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

Respuesta :

tonb
tonb tonb
  • 01-09-2021

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

Answer Link

Otras preguntas

can i get some help i dont get it
Solve the equation, if possible. -3|6n - 2| + 5 = 8
why do mangroove tree survive in the water?
Carbon-14 forms nitrogen-14 by a. alpha decay. b. beta decay. c. gamma decay. d. none of the above
1^2 + 4^2 + 7^2 + ... + (3n - 2)^2 = n(6n^2-3n-1)/2
what is the graph of an arithmetic sequence whose first term is 1 and whose common difference is 0.5?
I need help with. multiplication is there a 8 x s table trick
write 5 × 5 × 5 × 5 using exponents
in 1804, the 12th amendment changed the way the united states
The product of -8 and x is -96.