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

Which response best explains the narrator's attitude toward the events in the following passage (paragraphs 12-13)? When I first beheld this apparition--for I c
What is an equation of the line that passes through the points (-5, -8) and (-4,-6)? Put your answer in fully reduced form.​
The percent composition by mass of an unknown compound with a molecular mass of 90.078 u is 40.002% C, 6.7135% H, and 53.284% O. Determine the compound's empiri
hi does anyone like my drawings? share one of yours! CC drawings only or fnaf
List two types of details that help readers make inferences.
List three common states of matter and give definition
John measures the mass of a cup of chocolate milk and a glass of orange Juice. He places both containers on a balance scale. He observes that the scales tips fo
what is the land in the new England colonies like? How does this impact ability to farm?​
What is an object of symbolism in “The Tell-Tale Heart” by Edgar Allan Poe? Cannot be an object in the story. Why?
Write an equation in the form y= Mx + b for the line that has a slope of 1/4 and contains the point (12,3).