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

How does Douglass, in the Narrative of the Life of Frederick Douglass, try to change what his readers believe about what it means to be dedicated to the America
Explain the changes in the numbers between trophic levels as you go from producers to tertiary consumers in this ecological pyramid.
ANIMAL FARM UNIT TEST for English on edu i keep getting 60s pls helpppp
[Jack puts out his hand to take a sandwich. Algernon at once interferes. ] [Algernon. ] Please don’t touch the cucumber sandwiches. They are ordered specially f
visit a shop which sells sports shoes. observe the soles of shoes meant for various sports . describe your observations​
Question 3 of 10 A plant can have green (G) or yellow (9) leaves. It can also have a long (K) on short (k) stem. A scientist is preparing a Punnett square for a
HELP RIGHT NOW! in the book "Of Mice and Men" tell 2 things that are true and false about lennie small. NOT THE PERSONALITY/ TRAITS!
Question 3 of 10 A rectangle is a quadrilateral with four right angles.
Explain how the existence of imperfect markets has led to the establishment of subsidiaries in foreign markets.
HELP Please please plz