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

light hits ocean during ​
Bob wants to give Alice a necklace of n beads he originally has a long chain with caring beauty. Of each bead
Give reason for diversity of angiosperms
Show how you would convert 500 A.U. into light-years. Someone please help I’m so lost
with the use of relevant illustrations, discuss the view that expenditure approach= output approach= income approach ​
Write the number five and a quarter million in figures.
What is the solution to t - 3 < 12
Here is a rectangle. A (-3,0) D(-2,-3) B (3,2) C (4,-1) What is CD unit number?
a + b = c a + b + c =36 Given that a and b have the same value, work out the values of a,b and c
Need help with number 2 please!!!