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

1/2,5/10,7/8,2/3 which is bigger?
simplify 5a divided by 11a
Please Help! A cylinder shaped drum is used to store used motor oil. The drum has a height of 3 ft and a radius of 1.5 ft. How many cubic feet of oil does the d
In ptolemy’s earth-centered model, when would venus appear directly behind the sun as viewed from earth?
Which of the following best describes constructive forces? A. Forces that build up,or create,landmasses B. Forces that wear down or destroy land masses C. For
What differentiates LinkedIn from a "traditional" online job board such as Monster.com or CareerBuilder?
One less than a positive number times three more than that number is 32. Find the number. Let n= _____. (__)(__)=___
a rock is dropped from a height of 80 m and is in free fall what is the velocity of as it reaches the ground 4.0 seconds later
what is the reason that missouri compromise did not have lasting effects
What is the ultimate energy source for most wind? A) Earth’s revolution B) Earth’s rotation C) solar radiation D) tides