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

does someone mind helping me with this question? Thank you!
What new information did scientist learn from cashel man
An investigator would like to initiate a study to determine if the epidemiology of HIV infection is different in prisoner populations from that in non-prisoner
Write the solution to -9×+4<40??
Explain the goal of the Meiji Restoration in terms of who was to hold power. How was this different from Edo Japan?
What is a good slogan to advertise to someone visiting Earth?​
2. Which graph represents the change in cell surface area to volume ratio [1 mark] with increasing cell diameter? A. B. Surface area : volume ↑ Surface area : v
What can someone get if they want to buy a house now but do not have enough money to do so?
What is the value of the expression below when y=2 6y^2 +8y-9
During ____________ , an enzyme removes a ____________ functional group from the monomers of one organic molecule and a hydrogen from another monomer, linking m