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

Which compound is an electrolyte? (I) CH3CHO (3) CH3COOH (2) CH3OCH3 (4) CH3CH2CH3
What is one promise you make when you become a United States citizen?
Why do some states have more Representatives than other states?
What is A ∩ B?    Let set A = {odd numbers between 0 and 100} and set B = {numbers between 50 and 150 that are evenly divisible by 5}.
A large passenger aircraft accelerates down the runway for a distance of 3300 m before leaving the ground. It then climbs at a steady 6.3 degree angle.After the
Which statement describes a reversible reaction at equilibrium? (1) The activation energy of the forward reaction must equal the activation energy of the revers
Name one war fought by the United States in the 1800s.
what are the functions of Holloware
Who is the Commander in Chief of the military?
What is freedom of religion?