procedure SortByLastDigit(var arr: TArray); var i, j, temp: integer; begin for i := 0 to Length(arr) - 2 do begin for j := i + 1 to Length(arr) - 1 do begin if arr[i] mod 10 > arr[j] mod 10 then begin temp := arr[i]; arr[i] := arr[j]; arr[j] := temp; end; end; end; end;
program SortArrayByLastDigit;
type
TArray = array of integer;
var
arr: TArray;
i, j, temp: integer;
procedure SortByLastDigit(var arr: TArray);
var
i, j, temp: integer;
begin
for i := 0 to Length(arr) - 2 do
begin
for j := i + 1 to Length(arr) - 1 do
begin
if arr[i] mod 10 > arr[j] mod 10 then
begin
temp := arr[i];
arr[i] := arr[j];
arr[j] := temp;
end;
end;
end;
end;
begin
SetLength(arr, 5);
arr[0] := 123;
arr[1] := 456;
arr[2] := 789;
arr[3] := 321;
arr[4] := 654;
SortByLastDigit(arr);
for i := 0 to Length(arr) - 1 do
begin
writeln(arr[i]);
end;
end.