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

? QUESTION Laura is saving money to buy a bike that costs $125. She has $60 and will save an additional $5 each week. In how many weeks will she have enough mon
What is the culture in mauryan
king von rip im so sad
Help me . I honestly don't know . my brain isn't working
Evaluate Please help
HELP ASAP PLEASEEEEE!!!!!!!!!!!!!!
There is an animal farm where chickens and cows live. All together, there are 59 heads and 184 legs. How many chickens and cows are there on the farm?​
How does stress affect a person's hormones/endocrine system? (answer in a paragraph -- at least 8 sentences)
5,680÷80= WITH REMAINDER NO CALCULATOR IT WILL NOT WORK
North America is what of South America