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

At the time of Washingtons presidency which political party believed in states rights and opposed the national bank?
Michael scowls throughout "Seventh Grade" because he believes it willA.attract the girls'attentionB.make him seem ferocious.C.impress his older brother.D.show t
Please help me with this
The function h(x) = 12x8 + 49 is an even function which transformation of h(x) would result in a function that is neither even nor odd?
The school needs to buy new computers for four classrooms. If the school needs 20 new computers in each classroom, how many computers does it need to buy in tot
marcos y zamira conocer los materiales a la esuela
State the leading coefficient of the polynomial: f(x) = 6x^5 + 9x^4 + 2x^3 + 3x^2 - 4x -6
The maps show Georgia’s average temperature in January and July. Based on the maps, the city of most likely has the highest average yearly temperature.
Negative -5/8 - 1/2= I wanna know fast anyone??
Point L is on line segment KM. Given LM = 3x + 3, KM = 5x + 4, and KL = 5x + 1, determine the numerical length of KM.