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 the ratio of cups to quarts in a carton of milk? The choices are: [A] 1:1 [B] 1:4 [C] 4:1 [D] 4:5
If a mitochondrion has a length of 5 µm and a student’s drawing of the mitochondrion is 10 mm, what is the magnification of the drawing? A. ×0.0005 B. ×0.5 C. ×
What can homeless people see,hear,feel,smell,taste
Matt needs to pack in order for 1816 blocks. How can Matt pack the blocks without using boxes of 1000?
A _____ is a food that makes up a large portion of someone's diet. Please fill in the blank!!!
Is 9 feet greater less than or equal to 4 yards
An atom with a mass number of 234 and an atomic number of 90 has? A. 90 neutrons and 144 protons B. 234 neutrons and 90 protons C. 144 neutrons and 90 protons D
what is the greatest perimeter of 6 square centimeters
meteorologists notice a low-pressure area developing over warm ocean water. which type of storm is likely to form?
What is the value of x? Round your answer to the nearest tenth. x2 = 112