Selasa, 18 Desember 2012

Contoh Pengulangan Pada Turbo Pascal

Contoh 1 :
Uses Wincrt;
var
   i, j : integer;
begin
   for i := 1 to 5 do
   begin
      for j := i to 5 do
         write(j, ' ');
      writeln;
   end;
end.

bila program diatas dijalankan, hasilnya :

1 2 3 4 5
2 3 4 5
3 4 5
4 5
5



Contoh 2 :
Uses Wincrt;
const
b = 5;
var
a,c : integer;
begin
for a := b downto 1 do
begin
for c := 1 to a do
write(c, ' ');
writeln;
end;
end.

bila program diata dijalankan, hasilnya:

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Contoh 3 :
uses wincrt;
   var A,i,j:integer;
   begin
     clrscr;
     for i:= 5 downto 1 do
     begin
     A:=5;
     for j:= 1 to i do
     begin
     write(A:5);
     A:=A-1;
     end;
     writeln;
     end;
     readln;
   end.

bila program diatas dijalankan, hasilnya

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

Contoh 4 :
uses wincrt;
   var i, j: integer;
   begin
     clrscr;
     for i:= 1 to 5 do
     begin
     for j:= 1 to i do
     write(j:5); writeln;
     end;
     readln;
   end.

bila program diatas dijalankan, hasilnya :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Slamat mencoba, smoga berhasil.

0 komentar:

Posting Komentar