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

Q9. The solution of the form (b, - b) always satisfy the equation: a.x=-b c.y=x b.y = -a d.x+y=0​
Which function represents the graph of f(x) = -3|x| after it is translated 5 units down? - g(x) = -3|x| +5 - g(x)=-3x - 5| - g(x) = -3|x + 5| - g(x)=-3x - 5
In terms of biochemistry, what is a codon?
What is a central idea of "Perseus and the Quest for Medusa's Head"? Responses A. An angry king tries to shame Perseus, whom he hates, but the plan backfires w
how long does it take for the ball to travel 20 yards to the wide recevier if they are running 21 mph and the ball weighs 15 ounces
what is the meaning of customer in marketing?
a ____is a part of an experiment that does not change.
Which organism has the most available energy? sea urchin sea otter kelp elephant seal
Type your answer in the box. health includes the proactive steps you can take to reduce your risk of developing a disease and promote your health and well-being
Write happy birthday letter to a femal friend