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

The peace corps was created during the administration of what president?
Estimate the product by rounding each number to its greatest place value. 2,342 x 784.3 =
Can an object be increasing in speed as it's acceleration decreases?
Which activity is most likely to trigger secondary succession?
During the process of photosynthesis, energy from the sun is converted into?
what are some treaties america broke
784.4 rounded to the nearest cubic foot? a. 675 b.723 c.784 d.822
James would like to send a document he has saved on the hard drive to coworkers and Ireland Brazil and India. These coworkers have Internet access. He should
A local radio station had a contest to see who could guess closest to the actual number of jellybeans that filled a small car. the number of jellybeans that wer
Carbohydrates are more easily metabolized than lipids. However, on a gram-for-gram basis lipids provide cells with more