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

Compare victoria Falls to Niagara Falls. Which has the greater potential to generate energy?
what is 0.123 rounded to the nearest tenth
there are 798 calories in six 10-ounce bottles of apple juice. How many calories are there in one 10-ounce bottle of apple juice
To warm up before a run, David begins by completing quad and hurdler's stretches. Which of these accurately evaluates his choice of warm-up activities? a ) Thes
3. Irvin cut a 47 in. wire into two pieces. The longer piece is 13 in. longer than the shorter piece. What is the length of the longer piece? _________ in.Pleas
What does the word "valentine" mean?
What geographic feature made early Americans consider isolationist policies? having deserts on the Mexican border having fertile agricultural land on the Atlant
need help with math's home work 1 - increase 235 by 27% 2 - increase 24g by 9% 3 - decrease 1120 of 13.5% 4 - decrease 0.057 by 55% sally investment of £450 has
6(-2.3x-5)+(4x+11)= what is the answer
Near the surface of the earth what is the magnitude and direction of the acceleration due to gravity?