RosettaCodeData/Task/Fibonacci-sequence/Elena/fibonacci-sequence.elena

30 lines
399 B
Text
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
import extensions;
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
fibu(n)
{
2020-02-17 23:21:07 -08:00
int[] ac := new int[]::( 0,1 );
2019-09-12 10:33:56 -07:00
if (n < 2)
{
^ ac[n]
}
else
{
for(int i := 2, i <= n, i+=1)
{
int t := ac[1];
ac[1] := ac[0] + ac[1];
ac[0] := t
};
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
^ ac[1]
}
}
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
public program()
{
for(int i := 0, i <= 10, i+=1)
{
console.printLine(fibu(i))
}
}