Program Pengurut Data - Turbo Pascal | Pascal204™

Wednesday, August 1, 2012

Program Pengurut Data - Turbo Pascal

Program pengurutan_data;
uses wincrt;
const Max = 1000;
type Larik = array[1..Max] of integer;
var
L : Larik;
batas : integer;

           procedure masukan (var L : Larik; n : integer);
           var
                 a : integer;
           begin
             for a := 1 to n do
                 begin
                    write('Masukkan Nilai Ke-' ,a,' : '); readln(L[a]);
                    end;
                 end;
           procedure pengurutan (var L : Larik; n : integer);
           var
                 i : integer;
                 k : integer;
                 temp : integer;
           begin
             for i := 1 to (n-1) do
               for k := n downto i+1 do
                 if L[k] < L[k-1] then
                 begin
                 temp := L[k];
                 L[k] := L[k-1];
                 L[k-1] := temp;
               end;
             end;
           procedure keluaran(var L : Larik; n : integer);
           var
                i : integer;
           begin
             for i := 1 to n do
                    write(L[i]:5);
             end;
begin
  write('Masukkan Jumlah Elemen yang diinginkan : '); readln(batas); writeln;
  masukan(L,batas) ; writeln;
  pengurutan (L,batas); writeln;
  writeln('Hasil Pengurutan Larik :  ');
  keluaran(L,batas);
end.

No comments:

Post a Comment