home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Small Eiffel 0.4.8 / lib_show / fibonacci.e next >
Encoding:
Text File  |  1997-04-13  |  720 b   |  39 lines  |  [TEXT/ttxt]

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class FIBONACI
  5.  
  6. creation make
  7.  
  8. feature
  9.  
  10.    make is
  11.       do
  12.      if argument_count /= 1 or else
  13.         not argument(1).is_integer
  14.       then
  15.         io.put_string("Usage: ");
  16.         io.put_string(argument(0));
  17.         io.put_string(" <Integer_value>%N");
  18.         die_with_code(exit_failure_code);
  19.      end;
  20.      io.put_integer(fibonacci(argument(1).to_integer));
  21.      io.put_new_line;
  22.       end;
  23.  
  24.    fibonacci(i: INTEGER): INTEGER is
  25.       require
  26.      i >= 0
  27.       do
  28.      if i = 0 then
  29.         Result := 1;
  30.      elseif i = 1 then
  31.         Result := 1;
  32.      else
  33.         Result := fibonacci(i - 1) + fibonacci(i - 2) ;
  34.      end;
  35.       end;
  36.  
  37. end
  38.  
  39.