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

JBC Corp. declared a dividend of $2 per share, which was an increase of 25% from the prior year, yet JBC Corp. stock declined by 3% the day of the announcement.
In the following HI is parallel to JK What is the measurement of x?
simplify 6(2x+3y) + 3(x-y)
Principal = $5,400, rate = 18%, time = 2 years. What is the simple interest?
Which three things does many help people do in an economy?
¿Lo qué sabes sobre el coronavirus? 4. La enfermedad es transmitida por el __________________, contacto físico con personas _______________ y _____________.
why are pandemic preparation important
Which fraction is smallest? 4/35 OR 1/7 ?
b÷7−12=8 Solve the equation
The distance y (in miles) that a car travels on a highway in x minutes is represented by the equation y=1.1x. The graph shows the distance that a bus travels. F