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 ILL GIVE U BRAINLIST Explain an external control that maintains an ethic group's identity.
feel free to help me <3​
can y'all answer this please​
What is the molarity of a solution prepared from 25.0 grams of methanol (CH3OH, density = 0.792 g/mL) with 100.0 milliliters of ethanol (CH3CH2OH)? Assume the v
Need help ASAP!!!!!!!!
When you are doing some mindful listening what are you aware of?
Samuel is going to a carnival that has games and rides. Each game costs $2 and each ride costs $5. Samuel spent $60 altogether on 18 games and rides. Determine
give the position of Paramecium​
Is (−5,−8) a solution of y>3x+6
Congress had the power to levy taxes to pay for ports and forts necessary to protect the United States