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

100 points + brainliest:3​
I (not/go out) last Sunday because it (rain)
Find the slope and y-intercept of the line. 3x+4y=-7 write your answers in simplest form. slope : y - intercept : (spammers reported) will mark the brainliest.
No more crazy people plz just answer this question
In school of 600 pupils, 64% walk to school regularly. How many pupils walk to school regularly?
How can you apply content and context analysis of primary sources in hospitality industry?
Find the value of x.
Introducing a Topic Quick Check Introducing a Topic Quick Check Iten Amelia is writing an informative text about how to make a paper airplane. The audience is 1
Wind farms may be located far from users, which creates a challenge with: a. Transmitting electricity b. Finding land for wind farms C. The way wind farms look
difference of parallel structure and faulty parallel structure​