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

Three point charges are on the x axis: −1 µC at −3 m, 9 µC at the origin, and −5 µC at 3 m. Find the force on the first charge. The value of the Coulomb constan
1) You deposit $4800 in an account that pays 6.5% annual interest compounded continuously. What is the balance after three years to the nearest cent?
One set of instructions for an inherited trait a. seed b. gene c. phenotype d. allele
1. Eugene Talmadge was MOST LIKELY elected as Georgia's governor for a final time in 1946 because he
Just need B and C please
The end strength of the U.S. Coast Guard Reserve is _____ percent of the total Coast Guard. 10 20 30 50
One angle of an isosceles triangle measures 48°. Which other angles could be in that isosceles triangle?
Which market structure is BEST indicated by the photograph? A) monopoly B) oligopoly C) pure competition D) modified competition
-5=5(d+4) Please give step by step
. What 4 types of climates does Australia have?