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

what is demonstrated by water moving up a stream?A. evaporation and condensationB. sublimation and depositionC. cohesion and adhesionD. precipitation and transp
HELPPPP What is the cultural and historical significance of colonial literature?
What is 43 in exponential form?
Which diagram shows an example of refraction? W. X. Y. Z. A. Y B. X C. Z D. W
i need this help in math pls
I need the answer cause this is for a grade please!!! Jamie has a rectangular room in her home with a width of 8 feet and a diagonal distance of 17 feet. Find t
Which answer describes the type of sequence? 99, 33, 11, 113, ... neither arithmetic nor geometric arithmetic geometric
Classify each polygon by its number of sides. Drag the choices into the boxes to correctly classify each polygon.
I need help please, match these answers up.
How do my economic choices affect the environment?​