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 the main functions of lipids?
What builds proteins in a cell?
name three roles you play in your relationships with others. explain when you play each role.
Is Glass a good conductor of heat? is Metal a good conductor of heat? is wood a good conductor of heat
A person walks 25 m west and then 45 m at the angle of 60 degrees north of east what is the magnitude of the total displacement?
how are plains formed
the temperature on mars ranges widely from -207 f to 80 f find the average of the temperature extremes on mars
How many counting numbers are between 30 and 65, not including 30 and 65?
what's bigger 60% of 90 or half of 100?
Polished metals have a metallic luster, which means that?