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