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

name the type of subunits that form amylase
how do I solve this 8(c-9)=6(2c-12)-4c
Solve by addition 5x-2y=3 2x+7y=9
- 1/3 w = 5 & 3/8 a. w = 4 & 17/24 b. w = 5 & 1/24 c. w = 5 & 4/11 d. w = 5 & 17/24
how are evaporation and condensation the same? how are they different?
what are the levels of organization
to support a tree damaged in a storm, a 12-foot wire is secured from the ground to the tree at a point 10 feet off the ground. the tree meets the ground at a ri
mi hermano ___________ los estados unidos.
Why is frank lloyd wright famous? a. he was the lead engineer during the construction of the brooklyn bridge. b. he was an architect who integrated the natura
when citing sources for direct quotes, the only two things you need to include in a parenthetical citation are the author and the page number