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 cause the decline of the roman republic
76 is what percent of 95
what is -5\8 / 9\10 a) -1\36 b) -45\80 c) -25\36 d) -9\16 / = divided \ = part of fraction
A character who is a unique and a particular individual but at the same time is representative of all men is _____. concrete-universal flat
Which of the following shows the correct factorization of x3 - 5x2 - 14x? A. x(x + 7)(x + 2) B. x(x - 7)(x - 2) C. x(x + 7)(x - 2) D. x(x - 7)(x + 2)
What is the function (purpose) of the valves which connect the heart chambers? allows blood to flow between the two atria allows blood to flow between the two v
Which detail is part of the rising action of this story? The zoning board decides that the land can be used as a park. Mr. Peters is sitting on a bench on Cherr
Which is the most reasonable estimation for the weight of a kitten?
According to author Edgar Allen Poe, why did the short story become so viable in America? because authors could make money selling short stories to magazines
Is sushi causing exstinction