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

a ____ is how data values are arranged. the part of data set where the middle values are concentrated is called the ______ for data. A________ anticipates that
in this equation, is 6 a standard number. n + 6= 20
PLEASE HURRY I DONT HAVE MUCH TIME
If a car travels at an average speed of x miles per hour, how far would the car travel in 90 minutes?
what is the meaning of turn off?
How to create table/form libreoffice
I need help please ..
why do AED pads need to be placed one inch away from jewelry or pacemakers
what is the name for the "in between" phase in cell divisons
How do chemical companies contribute to acid deposition in the environment?