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 standard deck of cards contains 52 cards. One card is selected from the deck. ​(a) Compute the probability of randomly selecting a diamond or club. ​(b) Compu
need help with these questions
The magnesium reacts with the hydrochloric acid to produce a gas and a salt.What is the name of:the gas?​
A car costs £20000. Work out the price after a 5% discount.
Which model shows the correct factorization of x2 – x – 2? An algebra tile configuration. 3 tiles are in the Factor 1 spot: 1 is labeled + x and 2 are labeled +
what set of Transformations could be applied to rectangle ABCD to create A'B'C'D'?​
Which vector is the sum of the vectors shown below?
In circle P, diameter QS measures 20 centimeters. Circle P is shown. Line segment Q S is a diameter. Line segment R P is a radius. Angle R P S is 123 degrees. W
What does Loftus mean when she states that, "Memory is like a Wikipedia page?" Describe in good detail two examples given by Loftus that demonstrate how misinfo
In American Born Chinese, which event is an example of an internal conflict? A. Jin Wang struggles to accept his cultural identity. B. Wei-Chen punches Jin Wang