
Java Program to find factorial of a number
The calculation of factorial is pretty much an example of recursion technique in programming.
But there is a drawback that the recursion isn't memory efficient if you don't care about it, it isn't the problem for you.
It's a choice to save the time of a programmer.
The factorial of any number that is n > 1 multiplied by the factorial of n - 1. See the implementation.
for example
factorial(4)
4 * factorial(3)
4 * 3 * factorial(2)
4 * 3 * 2 * factorial(1)
The factorial of a positive integer x is equal to the product of all positive integers from 1 to x inclusively.
Also by definition, the factorial of 0 is 1.
download or see the complete code for calculating the factorial of a number in java
No comments:
Post a Comment