- Contoh 1 :
uses wincrt;
var nama:string;
umur,tahunlahir:integer;
begin
write('Nama : ');
readln(nama);
write('Tahun Lahir : ');
readln(tahunlahir);
umur:= 2011 - tahunlahir;
write('Umur : ', umur);
end.
- Contoh 2 :
uses wincrt;
var b,n:integer;
begin
n:=0;
repeat b:=1+3*n;
n:=n+1;
write (b, ' ');
until
n=6;
end.
- Contoh 3 :
program mahasiswa;
uses wincrt;
var
i:integer;
begin
i:=1; write(i);write(' ');
repeat
i:=i+3;
write(i);write(' ');
until i=16;
end.
- Contoh 4 :
program pemangkatan;
uses wincrt;
var a,b,i:integer;n:real;
begin
write('A = ');readln(a);
write('B = ');readln(b);
n:=1;
for i:=1 to abs(b) do
n:=n*a;
if (b>=0) then
begin
writeln('A pangkat B = ',n);
end
else
begin
writeln('A pangkat B = ',1/n);
end
end.
- Contoh 5 :program faktorial;
uses wincrt;
var a:real;
n,i:integer;
begin
write('n = ');readln(n);
write('n faktorial = ');
a:=1;
if n<0 then write('tidak terdefinisi')
else
if n<2 then
write(1)
else
begin
for i:=n downto 2 do
begin
write(i,' x ');
a:=a*i;
end;
write(1,' = ',a:0:0);
end;
end.
- Contoh 6 :program segitiga_pascal;
uses wincrt;
var
n,i,j,x:integer;
begin
n:=1;
read(x);
writeln(x);
for i:=1 to x do
begin
for j:= 1 to i do
begin
write(n,' ');
n:=n+1;
end;
writeln(' ');
end;
end.
- Contoh 7 :program deret_fibbonacci;
uses wincrt;
var a,b,c,i,n: integer;
begin
write('masukkan n = ');
readln(n);
a:=1; b:=0;
for i:=1 to n do
begin
c:=a+b;
a:=b;
b:=c;
write(c,',');
end;
end.
0 komentar:
Posting Komentar