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 do you find the area of a triangle when given only the lengths of three sides?
Nicki is working on developing one of her personality's auxiliary functions by focusing on what's happening "in the moment." What trait is Nicki working on?
The first three terms of a geometric sequence are as follows. -3, 15, -75 Find the next two terms of this sequence. Give exact values (not decimal approximation
Draw the alkyl bromide(s) you would use in a malonic ester synthesis of ethyl 2-methyl-4-pentenoate
If the electric potential in a region is given by v(x)=7/x2 the x component of the electric field in that region is
I know where to shop. Yo sabo dónde ir de compras. Yo conozco dónde ir de compras. Yo sé dónde ir de compras. Yo conoco dónde ir de compras.
pls help i need help with my history stuff
PLEASE HURRY Solve the inequality and express your answer in interval notation. x2 + 8x-7<0
Clad war at its height
The average weight of a male African elephant is 15,000 pounds. How many tons is this?