home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / vici_102 / examples / sqrt.e < prev    next >
Text File  |  1993-01-12  |  467b  |  28 lines

  1. class SQRT
  2. feature
  3.     
  4.     create is
  5.     do
  6.         io.putstring("Integer-Wurzel berechnen von: ");
  7.         io.readint;
  8.         io.putstring("Die Wurzel aus ");
  9.         io.putint(io.lastint);
  10.         io.putstring(" ist ");
  11.         io.putint(sqrt(io.lastint));
  12.         io.new_line;
  13.     end;
  14.     
  15.     sqrt(n: integer): integer is
  16.     require n >= 0
  17.     do
  18.         from
  19.         invariant Result^2 <= n
  20.         until (Result+1)^2 > n
  21.         loop
  22.             Result := Result + 1
  23.         end;
  24.     ensure Result^2 <= n and (Result+1)^2 > n
  25.     end;
  26.     
  27. end
  28.