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

The function F(x)=log5^x is decreasing.
Graph the equation. y= -1/6x-3
How does Reading Actively help?
Prophetic references to ____ are found in Chapters 34 and 37. The Messiah The return of the exiles The fall of babylon
Why was there little chance of success for clumsy thieves
Write a unit rate for the situation
Nominate a historical figure as "Most Influential Person of the 20th Century." Discuss two or three acccomplishments that set this person apart from all other c
The set of all points equidistant from the endpoints of a segment What term matches the definition? A) Central Angle B) Perpendicular Bisector C) Segment D
When making a citation for your MLA Works Cited page, if no author is listed, you _________________________ should begin with the medium of publication.
The table shows the monthly rainfall at a measuring station. What is the mean monthly rainfall? Round your answer to the nearest thousandth. The mean monthly ra