Monday, December 17, 2012

PROGRAM PASCAL SELECTION SORTING

program Selection;
uses crt;
var input : array [1..10] of integer;
banding,tukar,jumlah,i,j,k,l,temp:integer;
begin
clrscr;
writeln('PROGRAM TEKNIK SELECTION');
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-1 do
    begin
    k := j;
    for l := j+1 to jumlah do
        begin
        if input[k] > input[l] then
           begin
           k := l;
           end;
        banding:=banding+1;
        end;
    temp:=input[k];
    input[k] := input[j];
    input[j] := temp;
    tukar:=tukar+1;
    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