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

Find the slope of the line that goes through the given points (-1, 4), (5, 4)
A unified group of countries, the Communist bloc, was located in what world region?
3. After conducting interviews, you must determine
Bronze contains 90 to 95 percent copper and 5 to 10 percent tin. Because these percentages can vary, bronze is classified as (1) a compound (3) a mixture (2) an
An experiment produced 0.10 g CO2, with a volume of 0.056 L at STP. If the accepted density of CO2 at STP is 1.96 g/L, what is the approximate percent error?
In the ground state, which atom has a completely filled valence electron shell?(1) C (2) V (3) Ne (4)Sb
Raymond ran "x" miles on Tuesday. On Wednesday, he ran twice as far, but, on Thursday he only ran 1/2 Tuesday's distance. If Raymond ran a total of 9 miles on t
What causes mountain ranges to form?
explain how a grain of sand that wash up on a beach could end up some day as lava pouring from a volcano?
Which compound contains only covalent bonds?(1) NaOH (3) Ca(OH)2 (2) Ba(OH)2 (4) CH3OH