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

Identify the plural form of the word in parentheses. Sarasota is known for having some of the most beautiful (beach) in Florida.
Write a system of equations to describe the situation below, solve using substitution, and fill in the blanks. Last Wednesday, two friends met up after school t
Most dissolved carbon in the ocean is used to form which structure in marine organisms?
What is equal to 3log2 + log4
England negotiated with the United States over: Maine division from Massacusetts. the cost of cotton during the 1819 recession. the Oregon Country, divided at 5
How many delegates made up the legislative branch of Creek government?
Which of the following members of the Continental Congress just wanted reform and not independence? A. Samuel Adams B. Patrick Henry C. John Adams D. John D
"responses that lead to pleasurable consequences are more likely to be repeated." this is the law of:
6 times the sum of y and 11
Completar Following the pattern, write out the missing numbers in Spanish. 1. 50, 150, 250 ... 1.050 2. 5.000, 20.000, 35.000 ... 95.000 3. 100.000, 200.000, 30