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

you can drive on a gallon of gasoline. a test of a new car results in 300 miles on 20 gallons of gas . how far could you drive on 55 gallons of gas what is the
HELP ASAP WILL GIVE BRAINLYEST
n Which substance might lead to potentially dangerous addictions if abused? E herbal remedies O vitamins O mineral supplements O over-the-counter medications Ov
How do I solve this problem using the partition segment, line segments + chart included?
What decision did a London Court Reach In this case?
What is one of the core concepts in IT
In some cases, two or more pigments may overlap each other on the chromatogram, making it difficult to isolate and identify them. What are some things you could
ASAP Sara is recording water levels in the ocean near her home once an hour for one day. She observes the water level slowly rising and faling twice that day. W
. Using partial quotients, which would be the best choice for the first number to subtract in the division problem 673 Divided by 25?None of these is correct.25
Identify the given Mountain!​