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

An atom of an element has 10 protons. What is also true of that atom? A. It has 10 electrons. B. It has 10 isotopes. C. It has 10 neutrons. D. It has 10 ions.
Where might a slave captured farther south along the African coast, in the equatorial regions (around the equator), most likely have been shipped? A. North Amer
Where does the name "Black Hole" get it's name?
What is the gcf of 90 and 15
Which describes the characteristics of a liquid? A. It has no fixed volume or shape. B. It has a fixed volume and shape. C. It has high energy and expands to fi
Can someone plz tell me the question to this instead of saying something else than my questioned plz help me and don't mind about the writing in the pic it not
is it possible for an object not to be in motion and still have force acting upon it?
is 3/10 equivalent to 9/30
what is the answer for h/8=3/12 in algebra
is 3/4 less than or greater than 8/12