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

a car moving 50 miles per he speeds up steadily to 70 miles per he over a period of 30 minutes.how far did it travel during the 30 minute period of acceleration
a line passes through (3, –2) and (6, 2). a. write an equation for the line in point-slope form. b. rewrite the equation in standard form using integers. a. y m
the sum of two numbers is 56 . the larger number is 18 more than the smaller number. what are the numbers?
saturn is 9.54 au from the sun. what is its distance from the sun in kilometers? a. 14,000,000 km b. 15,723,270 km c. 57,000,000 km d. 1,431,000,000 km
what is the product? (9t − 4)(−9t − 4) −81t2 − 16 −81t2 16 −81t2 − 72t 16 −81t2 72t 16
order these numbers from least to greatest. 7.7 , −71517 , 49 , 18724
Can someone please help me understand Exponential Growth and Decay please?
Blood ph level is maintained by the respiratory system. true or false
which is not true about the alternation of generations? the life cycle of a plant alternates between diploid and haploid phases. gametophytes produce diploid ga
What is the minimum value of P=24x + 30y given the constraints