Factorial in D
Example for versions
D1,
D2,
gdc 0.24
This example uses recursive factorial definition.
module factorial;
import std.stdio;
ulong recursive(ulong x)
{
return (x == 0 ? 1 : x * recursive( x - 1 ));
}
int main()
{
for (int i = 0; i < 17; ++i)
{
writefln("%s! = %s", i, recursive(i));
}
return 0;
}
Comments
]]>blog comments powered by Disqus
]]>