Для четырёх чисел (Рассмотрим самый сложный случай, потому что все остальное делается по аналогии. Авторы-составители ЕГЭ проверяют этим заданием умение создавать алгоритмы с условными операторами):
/////////////////////////////////////////////////////////////////////////////////////////////////// Вариант 1
program minmax_for_four_numbers;
Function MyMin(x, y:double):double;
begin
if x>y then MyMin := y
else
MyMin := x;
end;
Function MyMax(x, y:double):double;
begin
if x>y then MyMax := x
else
MyMax := y;
end;
var a,b,c,d : double;
begin
writeln('Последовательно введите четыре числа, которые необходимо сравнить');
readLn(a,b,c,d);
writeLn('Min: ', MyMin(MyMin(a,b),MyMin(c,d)));
writeLn('Max: ', MyMax (MyMax (a,b),MyMax(c,d)));
end.
/////////////////////////////////////////////////////////////////////////////////////////////////// Вариант 2
var min_num, max_num, ent_num : double;
begin
writeln('Последовательно введите четыре числа, которые необходимо сравнить');
readLn(ent_num);
min_num := ent_num;
max_num := ent_num;
readLn(ent_num);
if ent_num < min_num then min_num := ent_num;
if ent_num > max_num then max_num := ent_num;
readLn(ent_num);
if ent_num < min_num then min_num := ent_num;
if ent_num > max_num then max_num := ent_num;
readLn(ent_num);
if ent_num < min_num then min_num := ent_num;
if ent_num > max_num then max_num := ent_num;
writeln('Max = ', max_num);
writeln('Mix = ', min_num);
end.
/////////////////////////////////////////////////////////////////////////////////////////////////// Вариант 3
program min_max_of_four_numbers_without_arrays_or_cycles;
var
summary, first_number, second_number, third_number, forth_number:real;
begin
writeln('Последовательно введите четыре числа, которые необходимо сравнить');
readln(first_number, second_number, third_number, forth_number);
if (first_number > second_number) and (first_number > third_number) and (first_number > forth_number) then
if (second_number < third_number) and (second_number < forth_number) then
begin
writeln('Max = ', first_number);
writeln('Min = ', second_number);
end
else if (third_number < second_number) and (third_number < forth_number) then
begin
writeln('Max = ', first_number);
writeln('Min = ', third_number);
end
else
begin
writeln('Max = ', first_number);
writeln('Min = ', forth_number);
end;
if (second_number > first_number) and (second_number > third_number) and (second_number > forth_number) then
if (first_number < third_number) and (first_number < forth_number) then
begin
writeln('Max = ', second_number);
writeln('Min = ', first_number);
end
else if (third_number < first_number) and (third_number < forth_number) then
begin
writeln('Max = ', second_number);
writeln('Min = ', third_number);
end
else
begin
writeln('Max = ', second_number);
writeln('Min = ', forth_number);
end;
if (third_number > first_number) and (third_number > second_number) and (third_number > forth_number) then
if (first_number < second_number) and (first_number < forth_number) then
begin
writeln('Max = ', third_number);
writeln('Min = ', first_number);
end
else if (second_number < first_number) and (second_number < forth_number) then
begin
writeln('Max = ', third_number);
writeln('Min = ', second_number);
end
else
begin
writeln('Max = ', third_number);
writeln('Min = ', forth_number);
end;
if (forth_number > first_number) and (forth_number > second_number) and (forth_number > third_number) then
if (first_number < second_number) and (first_number < third_number) then
begin
writeln('Max = ', forth_number);
writeln('Min = ', first_number);
end
else if (second_number < first_number) and (second_number < third_number) then
begin
writeln('Max = ', forth_number);
writeln('Min = ', second_number);
end
else
begin
writeln('Max = ', forth_number);
writeln('Min = ', third_number);
end;
end.