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

Gino is starring in the school play, it opens next week. Which revision best corrects the sentence? Gino is starring in the school play it opens next week. Gino
In eukaryotes, the citric acid cycle occurs in the _______, and the electron transport chain in the _______.
pls help me my English is bad :<​
can someone pls answer I need help with Question 15, 16, 17, and 18 and can someone please check if question 14 is correct? thank you if you help!!
What is a harmful consequence of hydroelectric power use? Dams release a lot of pollution downstream. Water released from a dam is colder and contains less oxy
How would the u. S. Defend against a nuclear attack?.
Which factors must work in concert to produce successful strategic execution?.
The author makes several references to Goldilocks throughout the article. To whom or what does the author compare Goldilocks? How do these comparisons contribut
Does this trend suggest American neutrality? Please support your answer.
Give an example of potential energy