Last active
January 16, 2021 22:14
-
-
Save jsbonso/e3d3559e843ff35e86ff6aef75161e3d to your computer and use it in GitHub Desktop.
Factorial Code Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Factorial | |
* | |
* 1. Get all factors (1, 2, 3 ... n) of a given number (n). | |
*. 2. Multiply all factors to get the value of the Factorial. | |
* | |
* Example: | |
* | |
* Factorial of 5: | |
* !5 = ? | |
* !5 = 5 * 4 * 3 * 2 * 1 | |
* !5 = 120 | |
* | |
*/ | |
int input = 5; | |
int temp = 1; | |
for (int i=1; i <= input; i++){ | |
temp = temp * i; | |
} | |
System.out.println("Factorial Result: " + temp); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment