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