PROGRAM MENGURUTKAN ANGKA DARI TERKECIL KE YANG TERBESAR DAN SEBALIKNYA
uses crt;
type
larik= array[1..15] of real;
var
i,j:integer;
l:real;
nilai:larik;
begin textbackground(7); textcolor(0); clrscr;
writeln;
writeln('MASUKAN DATA '); writeln;
for i:=1 to 15 do
begin
write('Masukkan Nilai[',i,'] : ') ; readln(nilai[i]);
end;
for j:=1 to 15-1 do
for i:=1 to 15-j do
if nilai[i]>nilai[i+1] then
begin
l:=nilai[i];
nilai[i]:=nilai[i+1];
nilai[i+1]:=l;
end;
writeln;
writeln('Data Setelah Diurutkan : ');
writeln;
for i:=1 to 15 do
write(nilai[i]:4:0);writeln;
for j:=1 to 15-1 do
for i:=1 to 15-j do
if nilai[i]<nilai[i+1] then
begin
l:=nilai[i];
nilai[i]:=nilai[i+1];
nilai[i+1]:=l;
end;
writeln;
writeln('Data Setelah Diurutkan : ');
writeln;
for i:=1 to 15 do
write(nilai[i]:4:0);
readln;
end.
Hasil RUNnya :
No comments:
Post a Comment