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

When was the battle of Hastings?
In the library there are 200 books. 58 of them are non-fiction. What percentage of the books are non-fiction?
Factor completely, the expression: 2x^3-2x^2-12x
What long-term effect do you think EU membership will have on nationalism in Europe? Explain.
Yolanda owns 4 rabbits. She expects the number of rabbits to double every year.a) after how many years will she have 64 rabbits?b) write and equation to model t
what percentage of 1457 is 898?
what describes the solvent in any solution
A certain test is worth 155 points. How many points (rounded to the nearest point) are needed to obtain a score of 65%?
What is a tonal collage? We learnt it in school BUT  I can't remember.
In a sale, normal prices are reduced by 12% The sale price of a digital camera is £132.88 Work out the normal price of the digital camera (3marks)