Last active
December 29, 2019 06:19
-
-
Save gsscoder/6a8b8a6d8151c388f19011947bc88c2a to your computer and use it in GitHub Desktop.
C# script to calculate factorial of a number
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
// $ dotnet script factorial.csx 10 | |
// 3628800 | |
var n = long.Parse(Args.ElementAt(0)); | |
Console.WriteLine($"{factorial(n)}"); | |
long factorial(long n) | |
{ | |
if (n == 0) { | |
return 1; | |
} | |
return n * factorial(n - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment