Uses Crt;
Var
 i,j,Top,Bottom,Left,Right :byte;
const
 f : array [1..7] of Real =
   (130.8, 146.8, 164.8, 174.6, 196.0, 220.0, 246.9);
{-----------------------------------------------------------}
Procedure Nota(a:real);
Begin
  sound(Round(a));
  delay(300);
  Nosound
End;
{-----------------------------------------------------------}
Procedure PlayMus;
Begin
  nota(f[1]);
  nota(f[3]);
  nota(f[5]);
  nota(f[5]);
  nota(f[3]);
  nota(f[5]);
  nota(f[3]);
  nota(f[5]);
  nota(f[1]);
  nota(f[3]);
  nota(f[1]);
  nota(f[3]);
  nota(f[5]);
  nota(f[5]);
  nota(f[4]);
  nota(f[5]);
  nota(f[4]);
  nota(f[5]);
  nota(f[7]);
  nota(f[4]);
  nota(f[1]);
  nota(f[3]);
  nota(f[5]);
  nota(f[5]);
  nota(f[3]);
  nota(f[5]);
  nota(f[3]);
  nota(f[5]);
  nota(f[1]);
  nota(f[3]);
  nota(f[1]);
  nota(f[3]);
  nota(f[1]);
  nota(f[1]);
  nota(f[3]);
  nota(f[5]);
  nota(f[3]);
  nota(f[4]);
  nota(f[4]);
  nota(f[5]);
  nota(f[7]);
  nota(f[4]);
  nota(f[7]);
  nota(f[4]);
  nota(f[7]);
  nota(f[7]);
  nota(f[2]);
  nota(f[6]);
  nota(f[6]);
  nota(f[4]);
  nota(f[6]);
  nota(f[4]);
  nota(f[6]);
  nota(f[7]);
  nota(f[4]);
End;
Procedure DrawTable(l,r,t,b:byte);
  Var a : byte;
  Const
   lg = LightGray;
  Begin
    TextColor(cyan);
    GotoXY(32,2);
    Write('Таблица умножения ');
    TextColor(LightMagenta);
    For a := 39-((abs(l-r)+1)*2)  to (abs(l-r) +1)*4 + (38 - (abs(l-r) * 2)) do
      Begin
        GotoXY(a, 14 - (abs(t-b)+1) div 2 );
        Write('═');
        GotoXY(a, (15-(abs(t-b)+1) div 2 ) + (abs(t-b)+1));
        Write('═');
      end;
    Write('╝');
    GotoXY(WhereX-1, WhereY - 1 - (abs(t-b)+1));
    Write('╗');
    TextColor(green);
    For a := l to r do
      begin
        GotoXY(37-((abs(l-r)+1)*2) + (a-l+1) * 4, 13 - (abs(t-b)+1) div 2);
        Write(a);
      end;
    For a := t to b do
      Begin
        GotoXY(36-(abs(l-r)+1)*2, (14 - (abs(t-b)+1) div 2 ) + a-t+1);
        If a < 10 then
          Begin
            TextColor(green);
            Write (a);
            TextColor(13);
            Write('  ║');
          end
        else begin
          TextColor(green);
          Write(a);
          TextColor(13);
          Write(' ║');
        end;
        GotoXY(WhereX-1, WhereY+1);
        Write('╚');
        GotoXY((41-(abs(l-r)+1)*2) + (abs(l-r)+1)*4,
        (14 - (abs(t-b)+1) div 2) + a - t +1);
        Write('║');
      end;
    GotoXY(39-((abs(l-r)+1)*2), 14 - (abs(t-b)+1) div 2);
    Write('╔')
  end; {DrawTable}
{----------------------------------------------------------}
Begin
  Clrscr;
  TextMode(CO80);
  TextColor(LightGray);
  Writeln('Введите числа до которых строить таблицу, разница между которыми ');
  Writeln('меньше 18 и произведение наибольших чисел меньше 1000 ');
  Write('в формате: левое правое верхнее нижнее (1 10 2 15): ');
  Read(Left, Right, Top , Bottom);
  While (abs(left-right) > 17) or (abs(top-bottom) > 17) or
  (right*bottom > 1000) do
    begin
      Write('Попробуйте снова ');
      Read(Left, Right, Top , Bottom);
    end;
  Clrscr;
  DrawTable(Left, Right, Top , Bottom);
  TextColor(yellow);
  For i := top to bottom do
    begin
      for j := left to right do
       begin
         GotoXY((37-(abs(left-right)+1)*2) + (J-left+1) * 4,
         (14 - (abs(top-bottom)+1) div 2) + i-top+1);
         Write(I*J);
       end;
    end;
  GotoXY(30,24);
  TextColor(Black);
  TextBackGround(Black);
  PlayMus;
  TextColor(red);
  Write('... Press any key ... ');
  TextColor(lightgray);
  ReadKey
End.


