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

Why can't plants and animals use the nitrogen directly from the atmosphere? Answer A.There is not enough of it in the air. B.Nitrogen gas contains the element i
Why did the Chinese peasants rebel against the manchus from 1850 to 1864?
Which of the following nutrient cycles has its largest reservoir in the atmosphere? A) Carbon cycle B) Nitrogen cycle C) Potassium cycle D) Phosphorus cycle E)
On average Exante Express trains are 50km/hr faster than Paral passenger trains. A Paral passenger train requires 60% more time then Exante train to travel 1800
what is the term for the condition where red blood shrivels?
It is likely that Earth could lose half of its species in the next ____________ years. a. 50 b. 100 c. 500 d. 1000
how far away is all 9 planets from the sun
Who benefitted from the corrupt bargain?
how far away is all 9 planets from the sun
What is the main difference between the right side and left side of the heart?