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

there’s literally a whole packet I have to do.
Identify the common difference of the sequence a, = -14 + 12(n-1) a) 12 b) - 1 c)-14 d) 1
living on domesticated herds of animals that feed on natural pasture is called
A cylinder has a volume of 288 pie cubic meters and a height of 9 meters. What is the area of the base?
please help me with this geometry question image attached
Please Help Me =) ----------------------------
what is an equation of the line containing the points (-1,5) and (3,9)​
About 2,000 small islands make up __________, which sits just east of the Philippines. Pacifica Polynesia Micronesia Melanesia I think the answer is Polynesia
Do you think defendants should have be found guilty beyond a reasonable doubt to be convicted?
On the main floor of a theatre the number of seats per row increases at a constant rate. Jack counts 31 seats in row 3 and 37 seats in row 6. How many seats are