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 an example of the kind of discrimination successfully ended by efforts of The National Organization for Women (NOW)?
What information would help a student make a good prediction about whether an object will float? A. knowing why some objects float B. measurements of othe
A 166-g hockey puck is gliding across the ice at 19.5 m/s. A player whacks it with her stick, sending it moving at 43.1 m/s at 45.0∘ to its initial direction of
What type of number is negative 5 eights
Three isotopes of argon occur in nature – 36 18Ar, 38 18Ar, 40 18Ar. Calculate the average atomic mass of argon to two decimal places, given the following relat
Approximate square root 18 to the nearest tenths plot the number on a number line
Is 6 to the square root rational or irrational
Which event is an example of irony in Macbeth?
Which student does NOT have a positive mind-set? I was confused about this question because all of these sound positive. A. Ralph wants to be the captain of th
The land needed to provide the resources for and assimilate the waste of a person or population is referred to as: an ecological footprint. natural interest. su