Advertisement
zyy12

Hal 34-35 Program urut_BUBBLE BAB 5

Mar 27th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. program urut_BUBBLE;
  2. uses crt;
  3. var i,j,k,temp,n : integer;
  4. A, B, C : array [1..100] of integer;
  5. begin
  6. clrscr; textcolor(12);
  7. write('Banyaknya Elemen Array : ') ; readln(n);
  8. {Input Data}
  9. for i := 1 to n do A[i] := random(1000);
  10. {Cetak Array Sebelum Pengurutan}
  11. writeln; textcolor(15);
  12. write('sebelum diurutkan : ');
  13. for i := 1 to n do write(A[i],' ');
  14. writeln; textcolor(15);
  15. writeln('Proses Pengurutan ]Bubble : ');
  16. for i := 1 to n-1 do begin
  17. for j := n downto i+1 do begin
  18. if A[j-1] > A [j] then begin
  19. temp := A[j-1];
  20. A[j] := temp;
  21. end;
  22. end;
  23. {Cetak Array tiap langkah pengurutan:}
  24. writeln; write('Hasil akhir langkah ke-',i,' : ');
  25. for k := 1 to n do write (A[k],' ');
  26. end;
  27. {Cetak Array Setelah Pengurutan}
  28. writeln; writeln;
  29. textcolor(15) ; write('Hasil Pengurutan Bubble : ')
  30. ; for i := 1 to n do write (A[i],' ');
  31. readln;
  32. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement