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

a swimming pool is 20 meters long and 12 meters wide the bottom of the pool is slanted so that the water depth is 1.3 at the shallow end and 4 meters deep at th
What is 9-4(2p-1)=45?
If (x − 2)^2=49, then x could be ?
a gasoline pump delivers 4 2/5 gallons of gas per minute. how many minutes will it take to fill a gas tank that holds 16 1/2 gallons?
Maria exercises for 2 1/7 hours every Saturday. She runs for 1/3 of the time that she exercises. How much time does she spend running every Saturday?
does gas have as definite or indefinite volume
how do I figure out what 5550/1000
Why didn't the first stars to form have solar systems with Earth like planets and satellites?
what is 89 divided by 6 in long divison
What is hyperbole? Please help