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

a small train at an amusement park is carrying passengers. half of the passengers are 6 years old, 110 are 7 years old, 15 are 8 years old, and 15 are 9 years o
Please help me answer the #107
Use the function below to find F(-2) F(X)= 3^x
Fre-e points 915 9482 0043 Gm1fgZ join
5 noun example pls give me answer​
What is the value of xxx in the figure shown below?
Question 2 of 10 What is true of a population? Select all that apply. A. All members live in the same area. B. All members have the same density. C. All members
Think back to the marathon in France. Write an equation to show the relationship between miles ran, y, and number of hours, x, if a racer was running 8 miles pe
Solve this questions:​
write an inequality that describes all the solutions to "-3(4" – x) + 6 < 9 – 2x.