Skip to content

Instantly share code, notes, and snippets.

@realeroberto
Last active February 6, 2016 14:32
Show Gist options
  • Save realeroberto/b682f83ea4f777202fa2 to your computer and use it in GitHub Desktop.
Save realeroberto/b682f83ea4f777202fa2 to your computer and use it in GitHub Desktop.
Tail-recursive factorial() in D.
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