home *** CD-ROM | disk | FTP | other *** search
- Program Fibonacci; { a famous series }
-
- uses crt, dos, vlncls;
-
- var
- i, key : integer;
- CountMax,StdVLNSize : integer;
- a, b, c, d : pVryLrgNo;
-
- begin
- { wksize is initialized to 100 words of storage }
- { but we make it larger before any memory is allocated }
- Setwksize(40);
- OpenTempRegs;
- { standard subs need temp storage }
- { their max count is wksize }
- { their needed storage is wksize*2+6 }
-
- CountMax := Getwksize div 4; { set count to anyvalue <= wksize }
- StdVLNSize := CountMax*2+6; {these variables need this much storage }
-
- getmem(a, StdVLNSize);
- getmem(b, StdVLNSize);
- getmem(c, StdVLNSize);
- getmem(d, StdVLNSize);
-
- a^.init(0,CountMax,1, nil);
- b^.init(0,CountMax,1, nil);
- c^.init(0,CountMax,1, nil);
- d^.init(0,CountMax,1, nil);
- writeln('--------------------------------');
-
- repeat;
- writeln;
- write('Enter Fibonacci Number - ');
- readln(key);
-
-
- b^.setsmall(0);
- write(' 1 '); b^.writeDecimal(0); writeln;
- c^.setsmall(1); { starting f numbers }
- write(' 2 '); c^.writeDecimal(0); writeln;
-
- if key>0 then
- for i := 3 to key do
- begin
- a^.copy(b);
- b^.copy(c);
- c^.addby(a);
- write(i:4,' ');
- c^.writeDecimal(0); writeln;
- if keypressed then break;
- end;
- until key = 0;
-
- writeln('--------------------------------');
- writeln('Done!');
-
- freemem(a, StdVLNSize);
- freemem(b, StdVLNSize);
- freemem(c, StdVLNSize);
- freemem(d, StdVLNSize);
-
- CloseTempRegs;
- end.