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 are four structures used for gas exchange
How do you solve y=3/4x+3 on a graph?
Kiemanh is solving the equation 15r-6r=36 . What is the value of r?
how did the Gobi and Taklamakan deserts affect early Chinese civilization? A.they allowed invaders easy access to attack the Chinese civilization B.They prevent
compare and contrast the properties of water from a glacier and a geyser
Identify the methods used to compensate for the scarcity of resources in the ancient world. How were resources used differently in the Neolithic Era? A. Hum
[ print page ] 02.06 Making Friends 02.06 Making Friends Voice Activity Choose 3 of the 5 questions below and respond to each with a complete Spanish sentence
how does f(4) if f(x) = 2x work? how do i work this out?
can someone make me a top brainiest
Can someone make my day and please help me solve number 3?