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

HELP NOW PLEASEEEEEEEEEIn the early years after Independence, the American people worked to create a new identity for themselves that was unique and independent
The principal of uniformitarian states that
Find the area of the regular decagon with a side measure of 4 cm. Give the answer to the nearest tenth.  Question 28 options: 129.4 cm2 246.2 cm2 123.1 cm2 139.
Pretend you’re an entomologist who’s giving a presentation about cicadas to nonscientists. How would you explain “swarmageddon” to them?
mi abuela me pide que le llevo pan. incorrecto o correcto
PLEASE NEED HELP REALLY BAD
Calculate the kinetic energy of a particle with a mass of 3.334 x 10-27 kg and a speed of 2.89 x 105 m/s
The world record for the hundred meter dash is 9.77 s. what is the corresponding average speed in units of m/s, km/h, ft/s, and mi/h?
Anyone please help I don’t understand this!
A small sphere with a charge of − 0.60 μc is placed in a uniform electric field of magnitude 1.2 × 106 n/c pointing to the west. what is the magnitude and direc