Guest User

Untitled

a guest
Apr 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 0.63 KB | None | 0 0
  1. with ada.Text_IO;   use ada.Text_IO;
  2.  
  3.  
  4.  
  5. procedure Fib
  6. is
  7.  
  8.    Store : array (1..45) of Integer;
  9.  
  10.  
  11.    function fibonacci (N : in Integer) return Integer
  12.    is
  13.       Result : Integer;
  14.    begin
  15.       if N > 2 then
  16.          Result := Store (N-2) + Store (N-1);
  17.       elsif N = 2 then
  18.          Result := 1;
  19.       else
  20.          Result := 0;
  21.       end if;
  22.  
  23.       Store (N) := Result;
  24.  
  25.       return Result;
  26.    end;
  27.  
  28.  
  29.    the_fib : Integer;
  30.  
  31. begin
  32.    for Each in Store'range loop
  33.       the_fib := fibonacci (Each);
  34.  
  35.       put_Line (Integer'Image (Each) & " => " & Integer'Image (Store (Each)));
  36.    end loop;
  37. end;
Add Comment
Please, Sign In to add comment