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

If a+b=6 and a-b = 4, what is the value of 2a + 3b?
If A+B=76  and A -B=38 whats A divided by B
A bag has index cards with the following numbers on them: 4, 11, 13, 25, 12, and 18. If an index card is drawn randomly , what is the probabilty that a composit
Which text exemplifies the anti-Victorianism prevalent in the early twentieth century? a) Eminent Victorians b) Jungle Books c) Philistine Victorians d) The
Hinge Joints-These jointscan only move in one direction, like a door hinge. One bone works against another. Movement is back and forth on one plane.Examples:___
what is 89 divided by 6 in long divison
What is Germany in German?
Why might nations join together to remove trade barriers?
What evidence in the declaration is there of religious faith? How do you think this religious faith influenced the ideals expressed in the declaration
How do I solve this equation? If 3t-7=5t then 6t=a 21b-7c-21d-42