home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_show / fibonacci.e next >
Text File  |  1999-06-05  |  2KB  |  51 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class FIBONACCI
  17.  
  18. creation make
  19.  
  20. feature
  21.  
  22.    make is
  23.       do
  24.          if argument_count /= 1 or else
  25.             not argument(1).is_integer
  26.           then
  27.             io.put_string("Usage: ");
  28.             io.put_string(argument(0));
  29.             io.put_string(" <Integer_value>%N");
  30.             die_with_code(exit_failure_code);
  31.          end;
  32.          io.put_integer(fibonacci(argument(1).to_integer));
  33.          io.put_new_line;
  34.       end;
  35.  
  36.    fibonacci(i: INTEGER): INTEGER is
  37.       require
  38.          i >= 0
  39.       do
  40.          if i = 0 then
  41.             Result := 1;
  42.          elseif i = 1 then
  43.             Result := 1;
  44.          else
  45.             Result := fibonacci(i - 1) + fibonacci(i - 2) ;
  46.          end;
  47.       end;
  48.  
  49. end
  50.  
  51.