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

in the number 13,407.036 there are two 3's. Explain how the values of the 3's are related.
What is the least common denominator for 5/6 and 3/8. 3/4 and 6/7
how were north american colonies all similar in the 1700s?
in the number 13,407.036 there are two 3's. Explain how the values of the 3's are related.
What is the least common denominator for 5/6 and 3/8. 3/4 and 6/7
you have a standard deck of 52 cards. you pick one card and then, with out putting the first card back, you pick a second card. what is the probability that bot
how were north american colonies all similar in the 1700s?
What were the major causes of WWII? Please include at least 4 answers.
What were the major causes of WWII? Please include at least 4 answers.
What are the functions of receptors in our body? Think of a situation where receptors do not work properly. What problems are likely to arise?