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

Can someone help me with the problem above.
What is true of the function
Who was the British scientist that broke the German Enigma Code in WWII?
Which of the following is NOT required to form strong moral character? A. knowing how to be the best at everything B. judging what is right and wrong C. believ
4(3x-2)+6x(2-1) simplified
1. how is 1,212,000 written in scientific notation? 2. how is 10,000,000,000 written in scientific notation? 3. how is 3.2 x 10^5 written in standard form 4. ho
Please I don’t understand this plz answer in detail
Collin, a nursing assistant at an assisted living facility, encouraged Anne, an older patient, to go to group bingo. How did Collin support the philosophy of re
NEED HELP ASAP WILL GIVE BRAINLIST IF CORRECT
Someone can help me?:(