Posted by wira on May 21st, 2010
Berikut ini adalah sebagian contoh perulangan dengan penerapan statemen For.. Do..
Uses Wincrt;
const
akhir = 4;
var
baris,kolom : integer;
begin
for baris := akhir downto 1 do
begin
for kolom := baris downto 1 do
write(kolom);
writeln;
end;
end.
Hasil :
4321
321
21
1
Uses Wincrt;
const
akhir = 4;
var
baris,kolom : integer;
begin
for baris := akhir downto 1 do
begin
for kolom := 1 to baris do
write(kolom);
writeln;
end;
end.
Hasil :
1234
123
12
1
Uses Wincrt;
const
akhir = 4;
var
baris,kolom : integer;
begin
for baris := 1 to akhir do
begin
for kolom := 1 to baris do
write(baris);
writeln;
end;
end.
Hasil :
1
22
333
4444
Uses Wincrt;
const
akhir = 4;
var
baris,kolom : integer;
begin
for baris := akhir downto 1 do
begin
for kolom := baris downto 1 do
write(baris);
writeln;
end;
end.
Hasil :
4444
333
22
1
Uses Wincrt;
const
akhir = 3;
var
baris,kolom : integer;
begin
for baris := akhir downto 1 do
begin
for kolom := baris downto 1 do
write(baris,' ',kolom);
writeln;
end;
end.
Hasil :
3 33 23 1
2 22 1
1 1
Uses wincrt;
var baris,kolom,jumbaris :integer;
begin
write ('Jumlah Baris : ');readln(jumbaris);
FOR BARIS:=1 TO jumbaris do
begin
write ('*': jumbaris baris);
FOR kolom := 2 TO (2 *baris -1 ) do
begin
write('*');
end;
writeln;
end;
end.
Tidak ada komentar:
Posting Komentar