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

Jim has gotten scores of 99 and 93 on his first two tests. what score must he get on his third test to keep an average of 90 or greater
Which chemical equation best describes the reaction of potassium metal with fluorine gas to form solid potassium fluoride? A. K(s) + F2(g) → KF2(s) B. K(s) + F(
How do we use the Pythagoras theorem in "everyday life".
What is the highest mountain on each continent?
Heat is released when H2 gas and O2 gas react to form H2O. Why? A. Breaking the H–H bond in H2 gas releases heat. B. Breaking the O–O bond in O2 gas releases he
What was the major purpose of the Truman Doctrine?
What is the highest mountain on each continent?
if Xx8=y is the rule,and the value of x is 4, what is the value of y
What is the highest mountain on each continent?
What's the other word stubborn; inflexible