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

Monica’s school band held a car wash to raise money for a trip to a parade in New York City. After washing 125 cars, they made $775 from a combination of $5.00
Which list of organisms consists of only consumers?
The professions of pharmacy and medicine began to split during the
Which compound can undergo an addition reaction? 1?
What is the major function of the valves found in human veins?
Counseling psychologist generally deal with more serious problems then do clinical psychologists
70 percent of magazines readers are women
Which formula can be used to find the nth term of a geometric sequence where the fifth term is 1/16 and the common ratio is 1/4?
Major events for for young adulthood can include all of the following except
why is it logical for the level of fsh to fall greatly following ovulation?