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

antonym for naturalist
The cost of two mopeds is the same as the cost of seven bicycles. The cost of one bicycle is $152. Therefore, the cost of one moped is
What profession is most likely to make use of amphoras and candelas
Why would this African ceremonial mask be worn? to cover the face of a criminal to learn from the teachings of a griot to communicate with ancestors
best way to dry a food thermometer
What is the correct scientific notation for 640,000,000? Question 5 options: 6.4X10^8 6.4X10^10 64X10^10 640X10^8
A software program that allows a programmer to type in code. modern versions usually make it easy to format the code on the screen.
A fountain on a lake sprays water in a parabolic arch modeled by the equation y = −0.4x2 + 3x, where y is the height in feet and x is the horizontal distance. A
Simplify 3 + (-8) -17
If the federal reserve decreases the reserve rate from 7% to 5%, how does this affect the amount of money that would result because of fraction-reserve rbanking