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

What’s the answer Evaluate 2^4
Highlight examples of metaphor in yellow and hyperbole in pink Rule thou in peace, our father, and our lord! Midst the remembrance of thy favours past, The mean
find the dimension of the missing side of a triangle given the following measurements: A=75 sq. ft, b=15 ft, h=?
Find the median of the following data. 46, 24,87, 64, 39, 50, 37, 48
Which of the following are benefits of well-named variables? Select two answers.
The _____ perspective on management consists of the systems, contingency, and quality-management viewpoints
.8787... as a fraction
Someone help please! I really need to finish this today.
According to the passage, what was the main reason that Pope Alexander VI sanctioned spanish colonization in the Americas?
What is 64 186 300 in standard form