home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / funct.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  944 b   |  44 lines

  1.                                        -- Chapter 8 - Program 6
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Funct is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    Twelve : INTEGER := 12;
  11.    Sum    : INTEGER;
  12.                             -- This is a function specification
  13.    function Square(Val : INTEGER) return INTEGER;
  14.  
  15.                             -- This is a function body
  16.    function Square(Val : INTEGER) return INTEGER is
  17.    begin
  18.       return Val * Val;
  19.    end Square;
  20.  
  21.    function Sum_Of_Numbers(Val1, Val2 : INTEGER) return INTEGER is
  22.    begin
  23.       return Val1 + Val2;
  24.    end Sum_Of_Numbers;
  25.  
  26. begin
  27.    Put("The square of 12 is");
  28.    Put(Square(Twelve));
  29.    New_line;
  30.    Sum := Sum_Of_Numbers(Twelve,12);
  31.    Put("The sum of 12 and 12 is");
  32.    Put(Sum);
  33.    New_Line;
  34. end Funct;
  35.  
  36.  
  37.  
  38.  
  39. -- Result of execution
  40.  
  41. -- The square of 12 is   144
  42. -- The sum of 12 and 12 is    24
  43.  
  44.