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 two subjects do most science illustrators have a background in?
The amino acid proline is one of the three amino acids that watson describes as having "special properties". what is special about proline?
Solve the nonlinear inequality. express the solution using interval notation. (x − 2)(x + 8) < 0 webassign
________ is an operant-conditioning procedure in which successive approximations of a desired response are reinforced. shaping spontaneous recovery stimulus gen
NEED HELP ASAP EXTRA POINTS Find the annual earnings if a worker is paid $743.75 semimonthly. Select one: a. $8,925.00 b. $17,850.00 c. $26,775.00
How were colonists able to support local businesses and communicate easily in new england?
When two objects with different charges are in the same area, the objects will (4 points) Select one: a. vibrate b. move away from each other c. attract each ot
a. vaporization b. freezing c. condensation d. melting
Suppose the first bill is passed, raising the probability of catching any given terrorist from 10% to 20%. however, this isn't enough for some. one representati
What is 30 rounding to the nearest ten