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

What is 30% off of 86
813-64 r²+r-8 factoring by grouping how do I solve​
Science HW Caelyn wanted to find out what shampoo made her hair the shiniest . Everyday she washed her hair with different shampoos and then rated how shiny her
what are reasons spain wanted to explore the new world
What is the pattern for -5, 10, -15, 20, -25
What is meant by "drawing the color line"?
Suppose you borrowed $112,500 at 5 ½ % interest on June 10 for 72 days. Your bank uses the exact interest method. Determine the amount of interest on the loan?
NEED HELP ASAP!! Our teacher never taught my class this and its on our homework. someone please help!!! i'll give brainliest to whoever is right
what is the rod of asclepius​
300 cubic inches to cubic centimeters