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

How to do 103,727,495 in expanded form
what is the outlet of a river called
factor completely if the polynomial is not factorable write prime also state the methods used to factor the polynomial. 1. x^2-12x+36 2. r^3-81r 3. 35x^3y
Please solve number 27.) -5(3-q) +4 =5q-11
Charlie has x state quarters. Ty has 3 more quarters than Charlie has. Vinnie has 2 times as many quarters as Ty has. Write and simplify an expression to show h
What was the casta system, and why was it created?
What problems brought on the tariff debates of 1827 and 1828? In what way did the South respond to northeastern demands for a higher tariff, and on what did the
A procedure designed to test a hypothesis
i need a paragraph on work experience like where i went ,what i did,what my boss was like and what i did during the work experience ? can anyone help?!
60 is 10 times as much as what?60 is 1/10 of what?