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

Which is a reason democracy failed following most Latin American Revolutions?
Civil war broke out in Nigeria because of conflict between a. nations. c. religious groups. b. ethnic groups. d. government officials.
An event leading to German surrender was: the uniting of Austria-Hungary the United States joining the Allies the Allies retreating from the Germans the surrend
What is the dependent variable? The more time David spent playing video games, the lower his grades became. A) Number of video games owned B) Points earned play
Please help! I need a short summary about the Chinese culture.
If something is made of atoms, it must be?
There are currently about ___________ Hispanics in the U.S. 20.000.000 45.000.000 150.000.000
the value of the x-intercept for the graph of 4x-5y=40
Unlike identical twins, fraternal twins a. result from the same fertilized egg. b. are always the same sex. c. result from two eggs fertilized by different s
A trapezoid and has an area of 45 square centimeters. If the base are 10 and 5 centimeters , what is the height of the trapezoid?