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

Federalist believed in the separation of powers because they wanted
How does hunger impact my school or community
what groups did nativists target
Which is the correct name of a compound that is formed by Si and O? silicon dioxide silicon trioxygen disilicon dioxygen monosilicon oxide
How does kinetic energy affect the stopping distance of a vehicle traveling at 30 mph compared to the same vehicle traveling at 60 mph?
Which activity related to selecting a topic for a literary analysis essay involves examining each element of the text carefully? A )drafting B) rewriting C) clo
What are 3 types of imperialism
which is greater 8/10 or 63/100 ?
Polio is a disease that can be transmitted by the bite of mammals. answer: true or false
Solve the system of equations. y = 7x + 43 y = 2x + 13