Listing program :
uses crt;
type
arr= array[1..50]of byte;
var
i: byte;
data: arr;
max: byte;
procedure input;
begin
clrscr;
write('Masukkan banyak data = ');
readln(max);
clrscr;
writeln('Masukkan ',max,' data');
writeln('=====================');
for i:= 1 to max do
begin
write('Data ke-',i,'= ');
readln(data[i]);
end;
clrscr;
for i:= 1 to max do
write(data[i], ' ');
writeln;
writeln('****************************');
writeln('Data yang telah diurutkan : ');
end;
procedure change(var a,b:byte);
var
c: byte;
begin
c:= a;
a:= b;
b:= c;
end;
procedure selection(var temp:arr; jmldata:integer);
var
i,j,lok: byte;
begin
for i:=1 to (jmldata-1) do
begin
lok := i;
for j:=(i+1) to jmldata do
if (temp[lok] > temp[j]) then lok := j;
change(temp[i],temp[lok]);
end;
end;
procedure output;
begin
writeln;
writeln('Ascending : ');
for i:= 1 to max do
write(data[i],' ');
writeln;
end;
begin
input;
selection(data,max);
output;
readkey;
end.
Comments
Post a Comment