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

Given side lengths of 15cm and 20cm, how many triangles can you build?​
I'LL GIVE BRAINLIEST....PLZ HELP ME!!Solve the following system of equations using substitution. Be sure to show all work and check your answer. y=5x+2 3x=-y+
Eloise is interested in buying a bungalow on the outskirts of the city. Her agent is reviewing the property details and informs her that there are several easem
Simplify this expression. -x -2y - 8x -2y
Create a list of 3 questions you would ask your favorite author. BONUS: if able, write a letter asking those questions. Could u please give me some question
In his explanation of the threshold frequency in the photoelectric effect, Einstein reasoned that the absorbed photon must have a minimum energy to dislodge an
anyone knows what 3(x-1)+x=4(x+2) is ??​
The house keeping staff
A 79.7 kg base runner begins his slide into second base while moving at a speed of 4.77 m/s. The coefficient of friction between his clothes and Earth is 0.635.
Select the correct answer. Which verb form correctly completes this sentence? Diego estaba muy cansado y por eso en un banco. O A. se sentaba O OB. se sentó o m