Friday, December 14, 2012

PROGRAM PASCAL TEKNIK EXCHANGE SORTING

program Exchange;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK EXCHANGE');
write('Masukkan jumlah data , maksimal 10 : ');readln(jumlah);
for i := 1 to jumlah do
    begin
        write('Masukkan data ke -',i,' : ');readln(input[i]);
    end;
for j:= 1 to jumlah do
    begin
    for k:= j+1 to jumlah do
        begin
        banding:=banding+1;
        if input[j]>input[k] then
            begin
            temp:=input[k];
            input[k]:=input[j];
            input[j]:=temp;
            tukar:=tukar+1;
            end;
        end;
    end;
for i:= 1 to jumlah do
begin
write('Data ke -',i,' yang sudah di sortir : ');writeln(input[i]);
end;
write('Jumlah perbandingan : ');writeln(banding);
write('Jumlah pertukaran : ');writeln(tukar);
readln;
end.

No comments:

Post a Comment