Procedure swap(var a, b: real); var t: real; begin t := a; a := b; b := t; end;
var a, b, c: real; begin readln(a, b, c); if (a > b) then swap(a, b); if (b > c) then swap(b, c); if (a > b) then swap(a, b); writeln(a, ' ', b, ' ', c); end.
Без процедур:
var a, b, c, t: integer; begin readln(a, b, c); if (a > b) then begin t := a; a := b; b := t; end; if (b > c) then begin t := b; b := c; c := t; end; if (a > b) then begin t := a; a := b; b := t; end; writeln(a, ' ', b, ' ', c); end.
Const n=3; var a: array[1..n] of integer; i, j, k: integer; begin randomize; write ('Исходный массив: '); for i := 1 to n do begin a[i] := random(256); write (a[i]:4); end; writeln; writeln; for i := 1 to n-1 do for j := 1 to n-i do if a[j] > a[j+1] then begin k := a[j]; a[j] := a[j+1]; a[j+1] := k end; write ('массив по возрастанию: '); for i := 1 to n do write(а[i]:4); writeln; readln; end.
var t: real;
begin
t := a;
a := b;
b := t;
end;
var a, b, c: real;
begin
readln(a, b, c);
if (a > b) then swap(a, b);
if (b > c) then swap(b, c);
if (a > b) then swap(a, b);
writeln(a, ' ', b, ' ', c);
end.
Без процедур:
var a, b, c, t: integer;
begin
readln(a, b, c);
if (a > b) then
begin
t := a;
a := b;
b := t;
end;
if (b > c) then
begin
t := b;
b := c;
c := t;
end;
if (a > b) then
begin
t := a;
a := b;
b := t;
end;
writeln(a, ' ', b, ' ', c);
end.
var a: array[1..n] of integer;
i, j, k: integer;
begin
randomize;
write ('Исходный массив: ');
for i := 1 to n do begin
a[i] := random(256);
write (a[i]:4); end;
writeln; writeln;
for i := 1 to n-1 do
for j := 1 to n-i do
if a[j] > a[j+1] then begin
k := a[j];
a[j] := a[j+1];
a[j+1] := k
end;
write ('массив по возрастанию: ');
for i := 1 to n do
write(а[i]:4);
writeln;
readln;
end.