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

I need help maxxxx points
George invited 65 students in his school to volunteer at a charity race. 39 of the students signed up to volunteer. What percent of the invited students signed
What went wrong on Dr. Olsen’s return trip to Earth?
Please select the best answer from the choices provided T F
Slobodan Milosevic was the leader of
What was the continuous air campaign begun by the United States in March 1965?
Can you please help me with this question
Harrison most likely decides to break out of jail because
Read the passage from “Cotton Is King” by James Henry Hammond. What is the speaker’s main argument in this excerpt? Without firing a gun, without drawing a swo
May someone please help me with this question?​