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 rectangle has a perimeter represented by the expression 6w+7, where is the width of the rectangle? Which statement best describes this rectangle? The express
The cost of fencing around a square field id rs.12000. if the cost of fencing per meter is rs. 30, find the area of the square field.
Pinunong militar ng mga sumerian
Rewards and Punishment examples
WILL GIVE BRAINLIEST FOR QUICK ANSWERS!! I RATE WELL FOR GOOD ANSWERS!
bakit nanakop ang kanlurang asy a
it states us to compare two columnsplease help me​
10 of the blocks are placed on top of each other to form a tower
please break this down and explain in detail
One may not claim the additional costs from the parents or guardians of uninvited children, to a wedding of social event. An invitation to a social gathering co