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 can you use a sequence of transformations to map a preimage to its image?
I need help with this English problem
How was president Andrew Jackson wrong for closing the bank
Translate we won’t drive tomorrow into Spanish in the box below:
Which excerpt from The Odyssey BEST demonstrates the importance of hospitality in Greek society?
Where did the first inhabitants of north america come from.
What is the level of sodium phosphate in the body?.
A number decreased by 25 is equal to 214. Find the number,
Which statistical measurements are $1 or less between Group B and Group A? the median and the mode the mean and the range the mean and the median the mode and t
causes of desertification​