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

How does the house have exhibit the seven characteristics of life
Is "a stitch in time saves nine" qualitative or quantitative?
Change the verb from passive to active voice. "Was struck" is the verb. The sentence is: "a tree on the golf course was struck by lightning"
What is the pathway of the stimulus from one neuron to the next?
In order to make up for a budget deficit, the government can do what?
Americans' concerns over immigration were originally heightened by religious disputes between which two faiths?
Please help. I am stuck on this algebra question: A homeowner wants to increase the size of his deck that now measures 15 feet by 18 feet. His homeowner's asso
what is 3x/10-2=x/5+2?
A regular trial jury at the state level is called a:
Need help with problem 25.