Contoh Program Buble Sort Mengunakan Lazarus


Berikut Script nya:

program project1;

{$mode objfpc}{$H+}


uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp
  { you can add units after this };
var
 i,n,j : integer;
 a : array [1..10] of integer;

procedure urutkan;
 var
  z : integer;

  begin
   for i:=1 to n-1 do
    begin
     for j:=n downto i+1 do
      begin
       if a[j] > a[j-1] then
        begin
         z:=a[j];
         a[j]:=a[j-1];
         a[j-1]:=z;
        end;
      end;
    end;
  end;

begin

 write ('Masukkan banyak data yang ingin di urut : '); readln(n);
 for i:=1 to n do
  begin
   write ('Data ',i,' : '); readln(a[i]);
  end;
 urutkan;
 write('Data setelah diurutkan : ');
 for j:=1 to n do
  write (a[j],' ');
readln;
end.


Click Me!
Previous
Next Post »