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

How do you solve the problem 3x+12=15
The fourth grade championship spelling bee began at 8:15 A.M. It lasted 3 hours and 48 minutes. What time did the spelling bee end?
4. ¿A cuál persona en la familia de Anabel no le gustaban los pedos? a. a su papá b. a Anabel C. a Lupe d. a su mamá
Which result would most likely increase mice population A: A long period drought B: A decrease in the food supply C: A decrease in the owl population
Which statement best describes how a beaver is interacting with a living part of its environment A: it is sharing a habitat with grasses B: it is moving throug
Which of the following to Mexico and the republic of Texas continue to fight about in the 1840s
In the poem “Barbara Frietchie,” what happened before Stonewall Jackson yelled, “Halt!”?
A 1,595 deposit for 10 years at a simple interest rate of 8% Interest: Total value:
x2 – 6x + 8 = 0 is x = 2. What is the other solution?
Factor the Difference of Square. 25x2 _ 16