Задача 6 Урок 9

Задача 6 Урок 9

Пользователь вводит три числа, найдите из них максимальное.
Решите тремя способами:
С использованием логической операции and.
С вложенными блоками (без and).
Без вложенных блоков (без and) -- запомнив максимум из двух в специальной переменной.

С использованием логической операции and.

var
  a, b, c : integer;
begin
  writeln('Enter the first number');
  readln (a);
  writeln('Enter the second number');
  readln(b);
  writeln('Enter the third number');
  readln(c);
  if ((a > b) and (a > c)) then
      writeln ('Maximum value a: ', a)
  else
      if ((b > a) and (b > c)) then
          writeln('Maximum value b: ', b)
      else
          writeln('Maximum value c: ', c);
  readln();
end.  

С вложенными блоками (без and).

var
  a, b, c : integer;
begin
  writeln('Enter the first number');
  readln (a);
  writeln('Enter the second number');
  readln(b);
  writeln('Enter the third number');
  readln(c);
  if (a > b) then
     if (a > c) then
        writeln ('Maximum value a:  ', a)
     else
        writeln('Maximum value c:  ', c)
  else
     if (b > c) then //если b больше a
        writeln('Maximum value b: ', b)
     else
         writeln ('Maximum value c: ', c);
  readln();
end.

Без вложенных блоков (без and) -- запомнив максимум из двух в специальной переменной.

var
  a, b, c : integer;
  greater_two, greater_three, max: integer;
begin
  writeln('Enter the first number');
  readln (a);
  writeln('Enter the second number');
  readln(b);
  writeln('Enter the third number');
  readln(c);
  if (a > b) then
     greater_two:= a
  else
    greater_two:= b;
  if (c > greater_two) then
     greater_three := c
  else
    greater_three := greater_two;
  max := greater_three;
  writeln('Maximum value: ', max);
  readln();
end.