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

I need help with world history can anybody answer this question? Which of the following choices gives an absolute location? a. northwest of the city limits b.
Is 500 is 10 times as much as 50 correct
117,821 round to the nearest ten thousand
PLEASE HELP!!! PLEASE HELP!!! PLEASE HELP!!! GOLDILOCKS AND BEARS How would a first person version "Goldilocks and the Three Bears" written from Goldilocks' poi
list 3 ways scientist can reduce bias
can a democracy have both representative and direct characteristics at the same time?
explain the relationship between observations and hypotheses
please help me solve 2,800 divided by 25
Write a description of an array of stickers using the product of 3 x 15.
How many meters are there in 4.80 ly ?