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

Tasha made 128 ounces of punch how many cups of punch did Latasha make
mike reads 5 pages an hour the independent variable is time what is the dependent variable
Can water boil at 0°?
What adds up to 14 and multiplies to negative 576?
Hi tech was signed in what year
What gas is removed from inhaled air
In The Metamorphosis, Kafka shows us how genres can overlap, making fiction seem like a more ( Versatile, concrete, psychological, or allegorical ) form of wr
What are the roles of women for the Mi'kmaq
Kites: Birds of Glory As a rule, raptors, or birds of prey, are among the most admired and adored birds in the world. From the California condor to the snowy ow
Why was the Gettysburg address forgotten in its time and remembered today?