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

please help me with these questions
What is 22.8 ÷ 15 = ??????...
Casey has n nickels. Megan has 4 times as many nickels as Casey has. Write an expression for the total number of nickels Casey and Megan have. Then simplify the
Regina purchased 1.75 pounds of turkey breast from her local deli for 5.99$ per pound to the nearest cent how much did she spend in all
Which statement can be used in blank b? a. <1 and <2 are supplementary. b. <1 and <2 are a linear pair. c. <2 and <3 are a linear pair. d. <
Mac bought forty-eight pounds of hamburger to store in his freezer. He put the hamburger in freezer bags that held two and two-thirds pounds each. How many free
Eddie finds a good deal on a used car that he likes. He makes a down payment of $450 and pays $199 a month for 36 months. What is the deferred price of the car
Apply the distributive property to simplify -1/3 (12+30)=?
what type of cell is produce in meiosis
Question 8 of 10 (1 point) Jump to Question: A train near Jason’s house just derailed. The local authorities said it is carrying hazardous chemicals and tha