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 led to the growth of factories in England in the eighteenth century? A. The increased size of families required people to look for alternative means of emp
The area of land where water is drained downhill into a body of water is known as a drainage basin, or _______.
(1/2)^2, 2/3, 0.45 write in correct order
Carrie is finding the set of even numbers within the set of prime numbers. She starts by considering only positive numbers. Of the sets described, which is the
Explain the meaning of a republican system of government and why it is successful.
4 sin ^ 2 x- 4 sin x + 1 = 0
What is the x-intercepts
In order to obtain a permit, food service establishments must first
What are the three most influential variables that affect electrical force?
What do the word cool mean ???