CONTOH PROGRAM MENGHITUNG NILAI PHI
program menghitung_phi;
uses wincrt ;
var
hasil :real;
begin
hasil:=22/7;
writeln(hasil);
end.
CONTOH PROGRAM KUADRAT DARI PENJUMLAHAN BILANGAN
program kuadrat_dari_jumlah;
uses wincrt;
var i,n:integer;
begin
read(n);
if n=1 then write (1);
if n>1 then
begin
for i:= n downto 2 do
write(2*i-1,'+');
write(1,'=');
write(sqr(n));
end;
end.
CONTOH PROGRAM URUTAN ANGKA
Program urutangka;
Uses winCrt;
Const
NMaks = 1000;
Type
Larik = Array [1..NMaks] of Integer;
Var
n : Integer;
bil : Larik;
Procedure Urut(var L:Larik; N:Integer);
Var
I : Integer;
K : Integer;
Temp : Integer;
Begin
For I:=1 to N-1 do
Begin
For K:=N downto I+1 do
Begin
If L[K] < L[K-1] then
Begin
Temp:=L[K];
L[K]:=L[K-1];
L[K-1]:=Temp;
End;
End;
End;
End;
Procedure ProsesUrut(L:Larik; N:Integer);
Var
k:integer;
Begin
For k:=1 to N do
Begin
Write('Data ke-',k,' : ');Readln(L[k]);
end;
Urut(L,N);
clrscr;
Writeln('Data Tersebut Setelah Diurutkan dari yang Terkecil ke yang Terbesar Menjadi : ');
For k:=1 to N do
Begin
Write(L[k],' ');
End;
End;
Begin
Clrscr;
writeln('*************************');
Writeln('Program Mengurutkan Angka');
writeln('*************************');
writeln;
Write('Masukkan Jumlah Data yang Ingin Diurutkan : ');Readln(n);
clrscr;
ProsesUrut(bil,n);
writeln;
End.
CONTOH PROGRAM MENGHITUNG UMUR LENGKAP
Program Menghitung_Umur_Seseorang;
uses wincrt;
var
d1,d2,m1,m2,y1,y2,H,I,J,K,L:integer;
begin
writeln('Menghitung umur seseorang');
writeln('Masukkan tanggal lahir = ');read(d1);
writeln('Masukkan bulan lahir = '); read(m1);
writeln('Masukkan tahun lahir = '); read(y1);
writeln('===============================');
writeln('Masukkan tanggal sekarang = ');read(d2);
writeln('Masukkan bulan sekarang = '); read(m2);
writeln('Masukkan tahun sekarang = '); read(y2);
H:=(y2-y1)*365+(m2-m1)*30+(d2-d1);
I:=H div 365;
J:=H mod 365;
K:=J div 30;
L:=J mod 30;
writeln('===============================');
write('umur anda sekarang adalah = ',I,' tahun ',K,' bulan ',L,' hari');
end.
CONTOH PROGRAM TABEL GAJI
program tabel gaji;
uses wincrt;
var
nama:array[1..10] of string;
alamat:array[1..20] of string;
jml_gaji:array[1..20] of real;
i,j:byte;
begin
write('masukan jumlah Data :');
readln(j);
for i:=1 to j do
begin
writeln('data ke- ',i);
write('nama Karyawan :');
readln(nama[i]);
write('masukan Alamat :');
readln(alamat[i]);
write('jumlah Gaji :');
readln(jml_gaji[i]);
end;
writeln('DATA GAJI KARYAWAN');
writeln('======================================');
writeln('No. Nama Karyawan Total Gaji');
writeln('=======================================');
for i:=1 to j do
begin
writeln(i:1,nama[i]:15,jml_gaji[i]:15:0);
end;
writeln('=======================================');
readln
end.
CONTOH PROGRAM SEGI EMPAT ANGKA
program angka;
uses wincrt;
var i,j,n,a:integer;
begin
write ('banyak suku ');
readln (n); a:=0;
for i:=1 to (n div 4)+1 do
begin
for j:=1 to 4 do
begin
a:=a+1;
if a<=n then
write (a,' ') else write(' ');
end;
writeln;
end;
end.
CONTOH PROGRAM MENGHITUNG EXPONENSIAL
program menghitung_exponensial;
uses wincrt;
var
i,n:integer;
e,f:real;
begin
e:=1; i:=0; n:=10; f:=1;
repeat
i:=i+1;
f:=f*i;
e:=e+1/f;
until i=n;
writeln('e= ', e:11:4);
end.
CONTOH PROGRAM MENGHITUNG BILANGAN PRIMA SAMPAI SERIBU
program jumlah_bilangan_prima_sampai_seribu;
uses wincrt;
var
batas : real;
i,j,jumlah :word;
prima: array[1..1000] of char;
begin
batas:=sqrt(1000);
jumlah:=0;
writeln('bilangan prima sampai dengan seribu: ');
writeln('------------------------------------');
writeln;
for i:=2 to 1000 do
begin
if prima[i]<>'*' then
begin
write(i:5);
jumlah:=jumlah+1;
if i<batas then
begin
j:=i;
while j<1000 do
begin
j:=j+i;
prima[j] := '*';
end;
end;
end;
end;
writeln;
writeln;
writeln;
writeln('ada sejumlah ',jumlah, ' bilangan prima');
end.
CONTOH PROGRAM MENGHITUNG BILANGAN PRIMA SAMPAI KE N
program bilangan_prima_antara_1_sd_n;
uses wincrt;
var
batas : real;
n:integer;
i,j,jumlah :word;
prima: array[1..1000] of char;
begin
write('bilangan prima antara 1 sampai dengan '); read (n);
writeln('------------------------------------');
batas:=sqrt(n);
jumlah:=0;
writeln;
for i:=2 to n do
begin
if prima[i]<>'*' then
begin
write(i:5);
jumlah:=jumlah+1;
if i<batas then
begin
j:=i;
while j<n do
begin
j:=j+i;
prima[j] := '*';
end;
end;
end;
end;
writeln;
writeln;
writeln;
writeln('ada sejumlah ',jumlah, ' bilangan prima');
end.
CONTOH PROGRAM MENGHITUNG NILAI INDEX PRESTASI
program SKS_IP_Semester;
uses wincrt;
type a=record
no:array[1..10] of integer;
nama:array[1..10] of string;
sks:array[1..10] of integer;
nilai:array[1..10] of string;
angka:array[1..10] of real;
SNA:array[1..10] of real;
end;
var b:a;
n,i:integer;
c,d,e:real;
procedure jmlsks(jml:integer;var sumsks:real;aaaa:a);
var j:integer;
begin sumsks:=0;
for j:=1 to jml do
sumsks:=sumsks+aaaa.sks[j];
end;
procedure jmlSNA(jml:integer;var sumSNA:real;aaaa:a);
var j:integer;
begin sumSNA:=0;
for j:=1 to jml do
sumSNA:=sumSNA+aaaa.SNA[j];
end;
begin write('jumlah mata kuliah = ');
readln(n);
for i:=1 to n do
begin
clrscr;
writeln('*masukkan data mata kuliah ke ',i,' *');
writeln;
b.no[i]:=i;
write('nama matkul = ');
readln(b.nama[i]);
write('jumlah sks = ');
readln(b.sks[i]);
write('nilai huruf (A/AB/B/BC/C/D/E) = ');
readln(b.nilai[i]);
if b.nilai[i]='A' then b.angka[i]:=4 else
if b.nilai[i]='AB' then b.angka[i]:=3.5 else
if b.nilai[i]='B' then b.angka[i]:=3 else
if b.nilai[i]='BC' then b.angka[i]:=2.5 else
if b.nilai[i]='C' then b.angka[i]:=2 else
if b.nilai[i]='D' then b.angka[i]:=1 else
b.angka[i]:=0;
b.SNA[i]:=b.sks[i]*b.angka[i];
writeln;
writeln;
end;
writeln('========================================================================');
writeln('no nama mata kuliah sks nilai huruf nilai angka SNA');
writeln('========================================================================');
for i:=1 to n do
writeln(b.no[i]:2,b.nama[i]:18,' ',b.sks[i]:4,' ',b.nilai[i]:7,' ',b.angka[i]:8:1,' ',b.SNA[i]:8:1);
writeln('========================================================================');
jmlsks(n,c,b);
jmlSNA(n,d,b);
e:=d/c;
writeln(' JUMLAH ',c:0:0,' ',d:3:1);
writeln;
writeln('Total SKS semester ini = ',c:3:2);
writeln('Total SNA semester ini = ',d:3:2);
writeln('Nilai IPS = ',e:3:2);
end.
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar