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 is the answer? x<-5 or x> -5? -1/5x-4>-3
which group of algae is responsible for formation of kelp-beds along north American coasts
In which of the sentences below is the shift in verb tense acceptable?Check all that apply. A.By the time I returned home three hours had passed. B.Though the w
When you sneeze, the air in your lungs accelerates from rest to approximately 150km/h in about 0.50 seconds. What is the acceleration, in units of g?
ben has 3 times as many guppies as goldfish. if he has a total of 20 fish, how many guppies does in have
What is the fraction of 16/48
Which sentence contains a misplaced modifier?  A.With loud shouts and screams, the Morenos felt the arena vibrate.  B.Soon, a loud buzzer sounded, and the playe
How do I get the solution for 4x-9=3.5x-9?
Name three countries, from the north-east north-west and southern hemisphere, for the tundra biome
what is 3/4 times 1/2 and what is 1.5 times 0.75 and then i need to figure out how much bigger the answer is to 1.5 times 0.75 is to 3/4 times 1/2