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 city lags far behind its neighbor due to its political and economic system? I WILL GIVE BRAINLIEST
how much would i have after 3 years if i invest $400 at 5% interest rate?
What was Askia the Great’s attitude toward learning?
plan of action to protec your salon clients and yourself
"Why do field researchers and laboratory researchers use tools that are similar and tools that are different?
HELP!! Water is added to two containers for 15 minutes. The equations below model the ounces of water, y, in each container after x minutes. At the time when th
What are dust Davils?
What are a sequence of equally distributed variables? A) Quota samples B) Convenience samples C) Cluster samples D) Random samples
-Why does the money in a savings account grow? It earns interest, plus it earns interest on the interest. A bank manager invests the money in the stock market.
HELP HELP HELP OVER HERE EXTRA POINTS