home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / math / verylarg / fibnacii.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-10-22  |  1.8 KB  |  65 lines

  1. Program Fibonacci;    { a famous series }
  2.  
  3. uses    crt, dos, vlncls;
  4.  
  5. var
  6.      i, key  : integer;
  7.      CountMax,StdVLNSize : integer;
  8.      a, b, c, d     : pVryLrgNo;
  9.  
  10. begin
  11.     { wksize is initialized to 100 words of storage }
  12.     { but we make it larger before any memory is allocated }
  13.     Setwksize(40);
  14.     OpenTempRegs;
  15.                             { standard subs need temp storage }
  16.                             { their max count is wksize      }
  17.                             { their needed storage is wksize*2+6 }
  18.  
  19.     CountMax := Getwksize div 4;      { set count to anyvalue <= wksize }
  20.     StdVLNSize := CountMax*2+6; {these variables need this much storage }
  21.  
  22.     getmem(a, StdVLNSize);
  23.     getmem(b, StdVLNSize);
  24.     getmem(c, StdVLNSize);
  25.     getmem(d, StdVLNSize);
  26.  
  27.     a^.init(0,CountMax,1, nil);
  28.     b^.init(0,CountMax,1, nil);
  29.     c^.init(0,CountMax,1, nil);
  30.     d^.init(0,CountMax,1, nil);
  31.     writeln('--------------------------------');
  32.  
  33.     repeat;
  34.        writeln;
  35.        write('Enter Fibonacci Number - ');
  36.        readln(key);
  37.  
  38.  
  39.        b^.setsmall(0);
  40.        write('   1   '); b^.writeDecimal(0);  writeln;
  41.        c^.setsmall(1);    { starting f numbers }
  42.        write('   2   '); c^.writeDecimal(0);  writeln;
  43.  
  44.        if key>0 then
  45.           for i := 3 to key do
  46.              begin
  47.               a^.copy(b);
  48.               b^.copy(c);
  49.               c^.addby(a);
  50.               write(i:4,'  ');
  51.               c^.writeDecimal(0);  writeln;
  52.               if keypressed then break;
  53.              end;
  54.     until key = 0;
  55.  
  56.     writeln('--------------------------------');
  57.     writeln('Done!');
  58.  
  59.     freemem(a, StdVLNSize);
  60.     freemem(b, StdVLNSize);
  61.     freemem(c, StdVLNSize);
  62.     freemem(d, StdVLNSize);
  63.  
  64.     CloseTempRegs;
  65.     end.