Last active
April 14, 2018 04:53
-
-
Save gushwell/d34899bc6a17d525ce537f7af619bfc1 to your computer and use it in GitHub Desktop.
C#で階乗の計算(再帰処理) ref: https://qiita.com/gushwell/items/51abfaa8bd05a38a5dd0
This file contains 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
public static long Factorial(int n) { | |
if (n == 0) | |
return 1L; | |
return n * Factorial(n - 1); | |
} |
This file contains 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
static long Factorial(int n) => | |
n == 0 ? 1L : n * Factorial(n - 1); |
This file contains 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
n! = n * (n-1) * (n-2) * ... * 3 * 2 * 1 (n > 0 のとき) | |
= 1 (n = 0 のとき) |
This file contains 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
(n-1) * (n-2) * ... * 3 * 2 * 1 |
This file contains 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
n! = n * (n-1)! |
This file contains 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
n! = n * (n-1)! (n > 0 のとき) | |
= 1 (n = 0 のとき) |
This file contains 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
public static long Factorial(int n) { | |
checked { | |
if (n == 0) | |
return 1L; | |
return n * Factorial(n - 1); | |
} | |
} |
This file contains 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
static long Factorial(int n) => | |
checked (n == 0 ? 1L : n * Factorial(n - 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment