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

ILL GIVE BRAINLIST PLS HELP
Question 1 All of the following statements are true of elements except: A. Elements are made of the same time of atom B. Elements can be made of atoms or molecu
7. The Expansion of American industry was sparked/caused mainly by?
What is meant by "division of powers," and how was this idea important to the creation of a new government?
1. Marisol: Oye, Víctor, ¿ (1) ayudas a buscar información por Internet para mi tarea de historia?
A Commercial Revolution: What were some effects of the growth of European capitalism?
what part of earth contains plates?
if you have, 196 chairs and you need to arrange them in an equal amount of row and columns, how many
Can someone please help me finish this all? I will give brainliest and a heart to the best answer!
How does the Gulf Stream climate cycle affect people who live in the North Atlantic region? A. They experience drought. B. They receive a lot of snowfall. C. T