Fibonacci numbers in Seed7
Example for versions
Seed7 2012-01-01
This example uses recursive definition of Fibonacci numbers.
$ include "seed7_05.s7i";
const func integer: fibonacci (in var integer: n) is func
result
var integer: result is 1;
begin
if n < 2 then
result := 1;
else
result := fibonacci(n - 1) + fibonacci(n - 2);
end if;
end func;
const proc: main is func
local
var integer: n is 0;
begin
for n range 0 to 15 do
write(fibonacci(n) <& ", ");
end for;
writeln("...");
end func;
Comments
]]>blog comments powered by Disqus
]]>