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

which value is equivalent to 7.3% written as a decimal? A. 0.73 B. 73.0 C. O.0073 D. 0.073
What two ways helpful bacteria work to keep you healthy
I want to study marine life, like dolphins and sharks. I should learn about _____.
Interphase must occur once before meiosis can happen. (Same thing for mitosis). What would happen if interphase didn’t occur first?
Worksheet titles and subtitles should be as wordy as possible. a. True b. False
A keyword should be just as confusing as the word you are trying to learn so you learn the concept better TRUE OR FALSE
compare and contrast the structure and function of these two tissue types: epithelial tissue and muscle tissue
La profesora _______ la clase. (6 letter word)(ends with an a)
What is 0.65 in expanded form
what is 6.549 to the nearest tenth