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

  1. Program Factorial;    { you choose how big }
  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 or smaller before any memory is allocated }
  13.     Setwksize(180);
  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 Factorial Number - ');
  36.        readln(key);
  37.  
  38.        a^.setsmall(1);
  39.  
  40.        if key>0 then
  41.           for i := 2 to key do
  42.              begin
  43.               a^.MulN(i);
  44.               write(i:4,'  ');
  45.               a^.writeDecimal(0);  writeln;
  46.               if keypressed then break;
  47.              end;
  48.     until key = 0;
  49.  
  50.     writeln('--------------------------------');
  51.     writeln('Done!');
  52.  
  53.     freemem(a, StdVLNSize);
  54.     freemem(b, StdVLNSize);
  55.     freemem(c, StdVLNSize);
  56.     freemem(d, StdVLNSize);
  57.  
  58.     CloseTempRegs;
  59.     end.