The Ada Program: pyramid.adb

  1 -- pyramid.adb: prints a pattern of letters in shape of pyramid
  2 
  3 with Ada.Text_IO;
  4 use Ada;
  5 
  6 --  For C='D', the   |   A
  7 --  output looks     |  ABA
  8 --  like this:       | ABCBA
  9 --                   |ABCDCBA
 10 
 11 procedure Pyramid is
 12 
 13    C: Character;
 14 
 15 begin
 16    Text_IO.Get (C);
 17 
 18    for M in 'A' .. C loop
 19 
 20       -- Spacing.  The number of spaces plus the number of
 21       -- chars in first half ('A'..M) must add upto 'A'..C
 22       for I in Character'Succ(M) .. C loop
 23          Text_IO.Put (' ');
 24       end loop;
 25 
 26       -- First half of line and the middle character
 27       for L in 'A' .. M loop
 28          Text_IO.Put (L);
 29       end loop;
 30 
 31       -- Second half of line
 32       for L in reverse 'A' .. Character'Pred(M) loop
 33          Text_IO.Put (L);
 34       end loop;
 35 
 36       Text_IO.New_Line;
 37 
 38    end loop;
 39 
 40 end Pyramid;