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 terms of the acronym smart what does it mean when a goal is a measurable
if the circumference of the circle below is 25 cm, what is the length of , to the nearest hundredth?
Please answer, I need help.
1. The length of a rectangle is four times its width. The perimeter of the rectangle is at most 130 cm.Which inequality models the relationship between the widt
What year did the Revolutionary War end?
if you answer 37 question correctly on a test, and received a score of 73%,how many questions were on the test
( 3 /4 ÷ 3 /100 −47/2 )÷4/2 · 2 /3 +7/6
Why is the minimum wage controversial? A. Opponents of the minimum wage argue that it harms business profits by lowering prices for consumers. B. Opponents of t
what is the ph of a 0.20 M solution of NH4Cl? [Kb(NH3) = 1.8 x 10^-5]
in NLM, M=(4x-4), L=(3x+12) and N=(6x+3). What is X? A. 9 B. 12 C. 13 D. 14