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

If five slices of pizza cost $5.50, how much do two slices cost? Ten slices? Half a slice ?
1) fought at Lexington and Concord 2)a formal meeting called for a special purpose 3) complaints against British rule 4) formed to solve the problem of trade
If a potato is allowed to dehydrate by sitting in open air, would the potato cells be more likely to absorb more water or less?
What is 258/300 written as a decimal and a percent???
Estimate each quotient using compatible numbers.
help me with this french hw plzz
help me with this french hw plzz
what is the proper or common noun in this sentence?The picture below is of the snow Festival in Sapporo.
Solve the equation for y.4x – 5y = 9
list the six enternal parts or peripherals of a computer system and identify which are output and which are input devices?