SRL Archive - Other Scripts

The Fibonacci Sequance


newguy45

2008-10-14 23:26:48

So I was bored today and decided to code the the Fibonacci Sequence



program FibonacciSequance;
var n1, n2, n3, repeatcount:integer;


procedure firstrun;
begin
n1:=0;
n2:=1;
n3:=n1+n2;
writeln(IntToStr(n1));
writeln(IntToStr(n2));
writeln(IntToStr(n3));
end;

procedure mainrun;
begin
n1:=n2
n2:=n3
n3:=n1+n2
writeln(IntToStr(n3));
end;

begin
repeatcount:=0;
firstrun;
repeat
repeatcount:=repeatcount+1
mainrun;
until(repeatcount = 15);
end.

The_Shermanator

2008-10-15 00:27:01

Only Reason I remembered this was from the book "The Davinci Code" lol which I only read the first couple chapters.

Fun thing to do with your time - I like to write SCAR codes during class:D

Successfully compiled (3524 ms)
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
Successfully executed

Daniel

2008-10-15 04:57:14

Fibonacci? Never heard of it, however, i get what it does.

Smartzkid

2008-10-15 16:16:58

Make one that creates pascal's triangle :p

   1
1 1
1 2 1
1 3 3 1

newguy45

2008-10-15 20:37:10

I might have to give that a shot smartzkid

Sandstorm

2008-10-15 20:53:40

What about that one, can't remember the name, but it goes like this:

1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
3 1 2 2 1 1
1 3 1 1 2 2 1 1
1 1 1 3 2 1 2 2 2 1
3 1 1 3 1 2 1 1 3 2 1 1
1 3 2 1 1 3 1 1 1 2 2 1 1 3 1 2 2 1
1 1 1 3 1 2 2 1 1 3 3 1 2 2 2 1 1 3 1 1 2 2 1 1

Etc.

So like:

One
One One
Two One
One Two, One One

etc.

:P.