SAMPLE PROGRAM IF
write('Masukkan lebar = ');
readln(l);
writeln;
writeln('PILIHAN');
writeln('1. Menghitung Luas');
writeln('2. Menghitung Keliling');
writeln('3. Menghitung Luas dan Keliling');
write('Masukkan pilihan = ');
readln(pil);
writeln;
IF pil = 1 THEN
writeln('Maka Luas Persegi Panjang = ',p*l:0:2)
ELSE IF pil = 2 THEN
writeln('Maka Keliling Persegi Panjang = ',2*(p+l):0:2)
ELSE IF pil = 3 THEN
BEGIN
writeln('Maka :');
writeln('Luas Persegi Panjang = ',p*l:0:2);
writeln('Keliling Persegi Panjang = ',2*(p+l):0:2);
END
ELSE
writeln('Pilihan yang Anda masukkan salah!');
readln;
End.
PROGRAM KONVERSI NILAI :
PROGRAM IFXE;
USES crt;
VAR
huruf:char;
nilai:integer;
BEGIN
clrscr;
writeln('PROGRAM KONVERSI ANGKA KE HURUF');
writeln('-------------------------------');
writeln('1. Nilai >=90 = A');
writeln('2. Nilai >=80 = B');
writeln('3. Nilai >=70 = C');
writeln('4. Nilai >=60 = D');
writeln('5. Nilai < 60 = E');
writeln('-----------------');
write('Masukkan nilai angka : ');readln(nilai);
IF nilai > 89 THEN
huruf:='A'
ELSE IF nilai > 79 THEN
huruf:='B'
ELSE IF nilai > 69 THEN
huruf:='C'
ELSE IF nilai > 59 THEN
huruf:='D'
ELSE
huruf:='E';
writeln;
writeln('Maka,');
writeln('Nilai angka = ',nilai);
writeln('Nilai huruf = ',huruf);
readln;
END.
SAMPLE PROGRAM FOR SEGITIGA
USES crt;
VAR
i,j,k,n,m,baris:integer;
BEGIN
clrscr;
write('Masukkan jumlah level : ');readln(n);
writeln;
baris:=n-1;
FOR i:=1 TO n DO
BEGIN
FOR m:=1 TO 5 DO
write(' ');
FOR k:=1 TO baris DO
write(' ');
FOR j:=1 TO i DO
write('# ');
baris:=baris-1;
writeln;
END;
readln;
END.
SAMPLE PROGRAM PERSEGI
USES crt;
VAR
n,i,j:integer;
BEGIN
clrscr;
writeln('MEMBENTUK BANGUN PERSEGI DENGAN LOOP');
writeln('====================================');
write('Masukkan ukuran persegi : ');readln(n);
writeln;
FOR i:=1 TO n DO
write('* ');
writeln;
FOR j:=1 TO n-2 DO
BEGIN
write('* ');
FOR i:=1 TO n-2 DO
write(' ');
write('*');
writeln;
END;
FOR i:=1 TO n DO
write('* ');
readln;
END.
Tidak ada komentar:
Posting Komentar