Last active
February 6, 2016 14:32
-
-
Save realeroberto/b682f83ea4f777202fa2 to your computer and use it in GitHub Desktop.
Tail-recursive factorial() in D.
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
import std.stdio; | |
ulong | |
factorial(int n) | |
{ | |
if(n < 2) | |
return 1; | |
else | |
return n * factorial(n - 1); | |
} | |
int | |
main() | |
{ | |
int n = 10; | |
ulong f = factorial(n); | |
writefln("%d! = %d", n, f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment