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

please help math question 40 pts
The kind of software that enables users to perform specific tasks is called _________ software
Which of the following statements does not describe a chemical property of oxygen: 1)Oxygen combines with carbon to form carbon dioxide gas 2) When coal is burn
When scientists looked at the polarity of bands of rock on either side of the mid-ocean ridges, what did they find? A. that there was no pattern B. that the
How many 40 tens make hundreds
Which was not created as a result of the National Security Act?
contains the Dome of the Rock, a holy site for Muslims contains the Wailing Wall, a holy site for Jews city where Jesus was crucified, making it a holy site for
g(x)= 3x − 3; Find g(−6)
what is 22.62 rounded to the nearest tenth
If the study only examines the actions of avatars, not the players behind them, what subfields of psychology might be involved in this research?