Contoh Program Perulangan

program coba_for;
uses wincrt;
label
a;
var
n,i,j:integer;
ulang : char;
begin
a:
clrscr;
writeln(‘===*Segitiga Angka*===’);
write(‘Masukkan Batas = ‘);readln(n);
writeln;
for i:=1 to n do
begin
for j:= 1 to i do
begin
write(i,’ ‘);
end;
writeln;
end;
writeln(‘—————‘);
writeln(‘Ingin mengulang?(Y/N)’);
readln(ulang);
if(ulang=’Y’) or (ulang=’y’) then Goto a;
if(ulang=’T’) or (ulang=’t’) then clrscr;
writeln(‘Terima kasih’);
writeln(‘Tekan enter untuk keluar’);
readln;
donewincrt;

end.
program coba_repeat;
uses wincrt;

var
n,i,j:integer;

begin
writeln(‘===*Bilangan Ganjil*===’);
write(‘Masukkan Batas Suku = ‘);readln(n);
i:=1;
repeat
write(i,’ ‘);
i:=i+2;
j:=j+1
until j=n;
end.

program coba_while;
uses wincrt;

var
n,i,j,k:integer;

begin
writeln(‘===*Bilangan Genap*===’);
write(‘Masukkan Batas Suku = ‘);readln(n);
i:=2;
while j<n do
begin
write(i,’ ‘);
i:=i+2;
j:=j+1;
end;
end.

program Deret_bilangan;
uses wincrt;
var
x:integer;

begin
writeln(‘==*Program deret bilangan*==’);
x:=1;
repeat
write(x,’ ‘);
x:=x+4;
until x>300;
writeln(”);
writeln(”);
write(‘Tekan enter untuk keluar’);
readln;
donewincrt;
end.

program kelipatan_5;
Uses wincrt;
var
x,y:longint;
begin
clrscr;
write(‘Berapa kelipatan 5 yang ingin ditampilkan = ‘);
readln(x);
writeln(‘================================’);
writeln(‘Hasil dari ‘,x,’ kelipatan 5  = ‘);
for x:=1 to x do
begin
y :=5*x;
write(y,’ ‘);
end;
writeln(”);
writeln(”);
write(‘Tekan enter untuk keluar’);
readln;
donewincrt;
end.

program ketupat_angka;
uses wincrt;
label
a;
var
n,i,j,k,pil : integer;
ulang : char;

begin
a:
clrscr;
writeln(‘===*Program Angka Belah Ketupat*===’);
write(‘Masukkan Batas : ‘);readln(n);
writeln;

for i := 1 to n do
begin
for k := (n-1) downto i do
begin
write(‘  ‘);
end;
for j := 1 to i do
begin
write (j,’ ‘);
end;
for j := (i-1) downto 1 do
begin
write(j,’ ‘);
end;
writeln(‘ ‘);

end;

for i := (n-1) downto 1 do
begin
for k := (n-1) downto i do
begin
write(‘  ‘);
end;
for j := 1 to i do
begin
write (j,’ ‘);
end;
for j := (i-1) downto 1 do
begin
write(j,’ ‘);
end;
writeln(‘ ‘);

end;
writeln(”);
writeln(‘==================’);
writeln(‘Ingin Mengulang?(Y/N)’);
read(ulang);
if(ulang=’Y’) or (ulang=’y’) then Goto a;
if(ulang=’T’) or (ulang=’t’) then clrscr;
readln;
writeln(‘Terima kasih’);
writeln(‘Tekan enter untuk keluar’);
readln;
donewincrt;
end.

program segitiga_angka;
uses wincrt;
var
a,b,n : integer;
begin
write(‘Masukkan batasan : ‘);readln(n);
for a:= 1 to n do
begin
for b:= 1 to a do
write(a);
writeln;
end;
writeln;
write(‘Tekan enter untuk keluar’);
readln;
donewincrt;
end.
program segitiga_angka;
uses wincrt;
var
a,b,n : integer;
begin
write(‘Masukkan batasan : ‘);readln(n);
for a:= 1 to n do
begin
for b:= 1 to a do
write(b);
writeln;
end;
writeln;
write(‘Tekan enter untuk keluar ‘);
readln;
donewincrt;
end.

program kelipatan_lima;
uses wincrt;
var
nilai : integer;
begin
writeln(‘Program Kelipatan Lima’);
writeln(‘======================’);
nilai := 0;
while nilai <= 50 do
begin
write(nilai,’ ‘);
nilai := nilai+5;
end;
writeln(”);
writeln(”);
writeln(‘Tekan enter untuk keluar’);
readln;
donewincrt;

end.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s