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 happened in 1776 that made Buenos Aires more important?
What is the science principle that explains magnetic fields? I need this fast, please!
Helppp it’s due in a couple minutes!!!
What the answer to x,y, and z
For an organism to be classified in the animal kingdom, which characteristics must the organism have?
$2.6 billion to develop a drug? new estimate makes questionable assumptions
Seven decreased by 13
To continue our talks of unit conversions I found this 160 square meter townhouse in Italy that is being sold for 157,000 Euros. Given 1 Euro =$1.18 U.S. the s
Which of the following terminating decimals is equivalent to. 3/8?a- 0.250 b- 0.376 c- 0.380d- 0.830​
HELP ASAP GIVING BRAINLIEST!!! There are other questions, feel free to answer. 14. A car worth $27,500 in 2012 is worth $16,720 in 2016. Find the rate of change