UNIVERSITAS DEHASEN
Wednesday, 15 January 2014
FUNGSI IF
PROGRAM PASCAL DATA PEGAWAI MENGGUNAKAN IF
Program dp;
uses wIncrt;
var np,nm,g:string[25];
t,h,gp,gk,gb :reaL;
u:char;
Begin
REPEAT
CLRSCR;
Write('nip = ');readln(np);
Write('nama = ');readln(nm);
Write('golongan = ');readln(g);
Write('tunjangan= ');readln(t);
Write('hutang = ');readln(h);
(*rumus*)
if g = 'IIIB' THEN BEGIN GP:=2000000 END
ELSE IF G = 'iiib'THEN BEGIN GP:= 2000000 END
ELSE GP:= 1500000;
GK:= GP + T;
GB:= GP - H;
WRITELN(' GAJI POKOK : ',GP:0:0);
WRITELN(' GAJI KOTOR : ',GK:0:0);
WRITELN(' GAJI BERSIH : ',GB:0:0);
writeln('masukan data kembali [Y/T] ' ); READLN (U);
UNTIL UPCASE (U) <> 'Y';
End.
Program dp;
uses wIncrt;
var np,nm,g:string[25];
t,h,gp,gk,gb :reaL;
u:char;
Begin
REPEAT
CLRSCR;
Write('nip = ');readln(np);
Write('nama = ');readln(nm);
Write('golongan = ');readln(g);
Write('tunjangan= ');readln(t);
Write('hutang = ');readln(h);
(*rumus*)
if g = 'IIIB' THEN BEGIN GP:=2000000 END
ELSE IF G = 'iiib'THEN BEGIN GP:= 2000000 END
ELSE GP:= 1500000;
GK:= GP + T;
GB:= GP - H;
WRITELN(' GAJI POKOK : ',GP:0:0);
WRITELN(' GAJI KOTOR : ',GK:0:0);
WRITELN(' GAJI BERSIH : ',GB:0:0);
writeln('masukan data kembali [Y/T] ' ); READLN (U);
UNTIL UPCASE (U) <> 'Y';
End.
Monday, 6 January 2014
kumpulan contoh pascal 2
a. median
Program median;
Uses Wincrt;
Var
x: array [1..100] of integer;
n,i,pos:integer;
md:real;
lagi:char;
Begin
lagi:='y';
while lagi='y' do
begin
writeln('=============');
Writeln('Program median');
Writeln('=============');
Writeln;
writeln('*dalam program mini ini, data yang harus dimasukkan nanti harus sudah urut*');
writeln;
Write('Masukkan Jumlah Data (n): ');
readln(n);
clrscr;
Writeln;
For i:= 1 to n do
Readln(x[i]);
Writeln;
For i:= 1 to n do
if (n mod 2 = 1) then
begin
pos:=(n div 2)+1;
md:=x[pos];
end
else
begin
pos:=(n div 2);
md:=(x[pos]+x[pos+1])/2;
end;
writeln;
Writeln('Median dari data berjumlah ', n,' tadi adalah : ',md:4:2);
writeln;
writeln('*terimakasih sudah menggunakan program ini*');
writeln('hitung lagi?');
readln(lagi);
end;
End.
b. mean
program rata_rata;
uses wincrt;
var
i,n: integer;
x,sum,mean:real;
begin
write('banyaknya data = ');
readln(n);
sum:=0;
for i:=1 to n do
begin
writeln('data ke',i,'=');
readln(x);
sum:=sum+x;
end;
mean:=sum/n;
writeln('rata-rata = ',mean:9:4);
end.
c.binominal
program binomial;
uses wincrt;
var
i,j,k,n,x:longint;
a,b,c,d,e,p:real;
begin
writeln('nilai n = ');readln(n);
writeln('nilai x dari n = ');readln(x);
writeln('peluang sukses p = ');readln(p);
a:=1;
b:=1;
c:=1;
d:=1;
e:=1;
for i:=1 to n do
a:=a*i;
for j:=1 to x do
begin
b:=b*j;
c:=c*p;
end;
for k:=1 to (n-x) do
begin
d:=d*k;
e:=e*(1-p);
end;
writeln(a/(b*d)*c*e:0:4);
end.
Program median;
Uses Wincrt;
Var
x: array [1..100] of integer;
n,i,pos:integer;
md:real;
lagi:char;
Begin
lagi:='y';
while lagi='y' do
begin
writeln('=============');
Writeln('Program median');
Writeln('=============');
Writeln;
writeln('*dalam program mini ini, data yang harus dimasukkan nanti harus sudah urut*');
writeln;
Write('Masukkan Jumlah Data (n): ');
readln(n);
clrscr;
Writeln;
For i:= 1 to n do
Readln(x[i]);
Writeln;
For i:= 1 to n do
if (n mod 2 = 1) then
begin
pos:=(n div 2)+1;
md:=x[pos];
end
else
begin
pos:=(n div 2);
md:=(x[pos]+x[pos+1])/2;
end;
writeln;
Writeln('Median dari data berjumlah ', n,' tadi adalah : ',md:4:2);
writeln;
writeln('*terimakasih sudah menggunakan program ini*');
writeln('hitung lagi?');
readln(lagi);
end;
End.
b. mean
program rata_rata;
uses wincrt;
var
i,n: integer;
x,sum,mean:real;
begin
write('banyaknya data = ');
readln(n);
sum:=0;
for i:=1 to n do
begin
writeln('data ke',i,'=');
readln(x);
sum:=sum+x;
end;
mean:=sum/n;
writeln('rata-rata = ',mean:9:4);
end.
c.binominal
program binomial;
uses wincrt;
var
i,j,k,n,x:longint;
a,b,c,d,e,p:real;
begin
writeln('nilai n = ');readln(n);
writeln('nilai x dari n = ');readln(x);
writeln('peluang sukses p = ');readln(p);
a:=1;
b:=1;
c:=1;
d:=1;
e:=1;
for i:=1 to n do
a:=a*i;
for j:=1 to x do
begin
b:=b*j;
c:=c*p;
end;
for k:=1 to (n-x) do
begin
d:=d*k;
e:=e*(1-p);
end;
writeln(a/(b*d)*c*e:0:4);
end.
kumpulan contoh pascal latihan 1
a. program konversi
program konversi;
uses wincrt ;
var
biner,desimal,sisa,b: integer ;
begin
desimal:=0; b:= 1;
writeln('Masukkan bilangan biner :');
readln(biner);
repeat
sisa := biner mod 10;
biner := biner div 10;
desimal := desimal + sisa * b;
b:= b*2;
until
biner =0;
writeln('Hasil konversi ke desimal adalah : ');
writeln(desimal);
end.
b. program deret aritmatika
program deret_aritmatika;
uses wincrt;
var
a,b,n,u:integer;
s:real;
begin
writeln('PROGRAM DERET ARITMATIKA');
writeln('————————');
write('a = ');readln(a);
write('b = ');readln(b);
write('n = ');readln(n);
s:=n*((2*a)+((n-1)*b))/2;
u:=a+((n-1)*b);
writeln('Un= ',u);
writeln('Sn= ',s:10:2);
end.
c. program deret fionacci
program deret_fibonacci;
uses wincrt;
function fibonacci(n:integer):integer;
begin
if n=0 then fibonacci:=0
else
if n=1 then fibonacci:=1
else
fibonacci:=fibonacci(n-1)+fibonacci(n-2);
end;
var
n, jumlah:integer;
begin
Write('Masukkan bilangan: ');readln(n);
for n:= 1 to n do
Writeln('Deret Fibonacci ke-',n,' adalah: ',fibonacci(n));
for n:= 1 to n do
jumlah:=fibonacci(n) + fibonacci(n)+ fibonacci(n-1)-1;
writeln('==================================');
writeln('jumlah fibonacci ke-’,n,’ adalah: ',jumlah);
readkey;
donewincrt;
end.
d. program deret
Program Deret;
Uses winCrt;
Var
a,b,n:integer;
begin
a:=1;
b:=1;
write('Jumlah Digit Deret yang anda inginkan: '); readln(n);
writeln;
while (b<=n) do
begin
write(a,' ');
a:=a+2 ;
b:=b+1 ;
end;
writeln;
writeln;
writeln('Jumlah seluruh deretnya adalah : ',sqr(n));
readln;
end.
program konversi;
uses wincrt ;
var
biner,desimal,sisa,b: integer ;
begin
desimal:=0; b:= 1;
writeln('Masukkan bilangan biner :');
readln(biner);
repeat
sisa := biner mod 10;
biner := biner div 10;
desimal := desimal + sisa * b;
b:= b*2;
until
biner =0;
writeln('Hasil konversi ke desimal adalah : ');
writeln(desimal);
end.
b. program deret aritmatika
program deret_aritmatika;
uses wincrt;
var
a,b,n,u:integer;
s:real;
begin
writeln('PROGRAM DERET ARITMATIKA');
writeln('————————');
write('a = ');readln(a);
write('b = ');readln(b);
write('n = ');readln(n);
s:=n*((2*a)+((n-1)*b))/2;
u:=a+((n-1)*b);
writeln('Un= ',u);
writeln('Sn= ',s:10:2);
end.
c. program deret fionacci
program deret_fibonacci;
uses wincrt;
function fibonacci(n:integer):integer;
begin
if n=0 then fibonacci:=0
else
if n=1 then fibonacci:=1
else
fibonacci:=fibonacci(n-1)+fibonacci(n-2);
end;
var
n, jumlah:integer;
begin
Write('Masukkan bilangan: ');readln(n);
for n:= 1 to n do
Writeln('Deret Fibonacci ke-',n,' adalah: ',fibonacci(n));
for n:= 1 to n do
jumlah:=fibonacci(n) + fibonacci(n)+ fibonacci(n-1)-1;
writeln('==================================');
writeln('jumlah fibonacci ke-’,n,’ adalah: ',jumlah);
readkey;
donewincrt;
end.
d. program deret
Program Deret;
Uses winCrt;
Var
a,b,n:integer;
begin
a:=1;
b:=1;
write('Jumlah Digit Deret yang anda inginkan: '); readln(n);
writeln;
while (b<=n) do
begin
write(a,' ');
a:=a+2 ;
b:=b+1 ;
end;
writeln;
writeln;
writeln('Jumlah seluruh deretnya adalah : ',sqr(n));
readln;
end.
e. deret genap
program deret_genap;
uses wincrt;
var
i:integer;
begin
i:=2; write(2,' ');
repeat
i:=i+2; write(i,' ');
until i=10;
end.
f. program kombinasi
program permutasi_kombinasi;
uses wincrt;
var
a,b,a_k,kombinasi,permutasi:real;
i,n,k:longint;
begin
writeln('MENGHITUNG PERMUTASI DAN KOMBINASI:');
write('masukkan bilangan n = ');readln(n);
write('masukkan bilangan k = ');readln (k);
a:=1;
b:=1;
a_k:=1;
for i:=2 to n do
a := a*i;
for i:=2 to k do
b :=b*i;
for i :=2 to (n-k) do
a_k := a_k * i;
kombinasi := a/(b*a_k);
permutasi :=a/ (a_k);
writeln ( n, ' Kombinasi',k,' = ', kombinasi:4:1);
writeln (n, ' Permutasi',k,' = ',permutasi :4:1);
end.
g. median
Program median;
Uses Wincrt;
Var
x: array [1..100] of integer;
n,i,pos:integer;
md:real;
lagi:char;
Begin
lagi:='y';
while lagi='y' do
begin
writeln('=============');
Writeln('Program median');
Writeln('=============');
Writeln;
writeln('*dalam program mini ini, data yang harus dimasukkan nanti harus sudah urut*');
writeln;
Write('Masukkan Jumlah Data (n): ');
readln(n);
clrscr;
Writeln;
For i:= 1 to n do
Readln(x[i]);
Writeln;
For i:= 1 to n do
if (n mod 2 = 1) then
begin
pos:=(n div 2)+1;
md:=x[pos];
end
else
begin
pos:=(n div 2);
md:=(x[pos]+x[pos+1])/2;
end;
writeln;
Writeln('Median dari data berjumlah ', n,' tadi adalah : ',md:4:2);
writeln;
writeln('*terimakasih sudah menggunakan program ini*');
writeln('hitung lagi?');
readln(lagi);
end;
End.
kumpulan contoh pascal
a. program taxi
program ricky_taxi;
uses wincrt;
Var Jarak,Bayar:real;
begin
clrscr;
write('masukan jarak = ');readln(jarak);
if(jarak<=1)then
bayar:=750 else
Bayar :=750+(350*(jarak-1));
write('pembayaran adalah : Rp. ',bayar:3:0);
readln;
write ('RICky TAxi');
readln;
end.
b. program pangkat
program pangkat;
uses wincrt;
var pang,i,n,a:real;
begin
clrscr;
i:=1;
pang:=1;
write('masukan nilai a: ');readln(a);
write('masukan nilai n: ');readln(n);
while (i<=n)
do begin
pang:=pang*a;
i:=i+1;
end;
write('pangkat', pang:6:0);
readln;
end.
C. Array berdimensi
program array_berdimensi_1;
uses wincrt;
var
nim :array[1..5]of string[7];
nama:array[1..5]of string[15];
ipk :array[1..5]of real;
i,j:byte;
begin
clrscr;
for i:=1 to 5 do
begin
writeln('Data mahasiswa ke : ',i);
write('masukan NIM mahasiswa : ');readln(nim[i]);
write('masukan NAMA mahasiswa: ');readln(nama[i]);
write('masukan IPK mahasiswa : ');readln(ipk [i]);
writeln('=======================');
end;
writeln('DAFTAR NILAI IPK MAHASISWA');
writeln('……………………..');
writeln(' NIM NAMA IPK');
writeln('…….. ……………');
for j:=1 TO 5 DO
begin
writeln(nim[j],' ',nama[j],' ',IPK[j]:2:2);
end;
writeln('…….. ……………..');
end.
program ricky_taxi;
uses wincrt;
Var Jarak,Bayar:real;
begin
clrscr;
write('masukan jarak = ');readln(jarak);
if(jarak<=1)then
bayar:=750 else
Bayar :=750+(350*(jarak-1));
write('pembayaran adalah : Rp. ',bayar:3:0);
readln;
write ('RICky TAxi');
readln;
end.
b. program pangkat
program pangkat;
uses wincrt;
var pang,i,n,a:real;
begin
clrscr;
i:=1;
pang:=1;
write('masukan nilai a: ');readln(a);
write('masukan nilai n: ');readln(n);
while (i<=n)
do begin
pang:=pang*a;
i:=i+1;
end;
write('pangkat', pang:6:0);
readln;
end.
C. Array berdimensi
program array_berdimensi_1;
uses wincrt;
var
nim :array[1..5]of string[7];
nama:array[1..5]of string[15];
ipk :array[1..5]of real;
i,j:byte;
begin
clrscr;
for i:=1 to 5 do
begin
writeln('Data mahasiswa ke : ',i);
write('masukan NIM mahasiswa : ');readln(nim[i]);
write('masukan NAMA mahasiswa: ');readln(nama[i]);
write('masukan IPK mahasiswa : ');readln(ipk [i]);
writeln('=======================');
end;
writeln('DAFTAR NILAI IPK MAHASISWA');
writeln('……………………..');
writeln(' NIM NAMA IPK');
writeln('…….. ……………');
for j:=1 TO 5 DO
begin
writeln(nim[j],' ',nama[j],' ',IPK[j]:2:2);
end;
writeln('…….. ……………..');
end.
Sunday, 5 January 2014
program pascal menggunakan array
Program kartun1;
Uses wincrt;
Const
max=5;
Type
kartun=array[1..max] of string[10];
Var
Jnskartun :kartun;
i:integer;
begin
For i:=1 to max do
Jnskartun[1]:='bleach';
Jnskartun[2]:='byakugan';
Jnskartun[3]:='Naruto';
Jnskartun[4]:='one piece';
Jnskartun[5]:='Avatar';
For i:=1 to max do
writeln(i,'. ',Jnskartun[i]);
end.
Uses wincrt;
Const
max=5;
Type
kartun=array[1..max] of string[10];
Var
Jnskartun :kartun;
i:integer;
begin
For i:=1 to max do
Jnskartun[1]:='bleach';
Jnskartun[2]:='byakugan';
Jnskartun[3]:='Naruto';
Jnskartun[4]:='one piece';
Jnskartun[5]:='Avatar';
For i:=1 to max do
writeln(i,'. ',Jnskartun[i]);
end.
contoh perulangan pascal repeat until
program repeat_until;
uses wincrt;
label back;
var
k,awal,akhir:integer;
rata,jum:real;
begin
back:
clrscr;
write('nilai awal = ');readln(awal);
write('nilai akhir = ');readln(akhir);
if awal<=akhir then
begin
repeat
jum:=jum+awal;
awal:=awal+2;
k:=k+1;
until awal>akhir;
end
else goto back;
rata:=jum/k;
writeln('rata-rata= ',rata:2:2);
write('================================================================================');
writeln(' ==*RICKYSEPRIYANTO_13010241*==');
writeln(' ==================================');
end.
B. PROGRAM REPEAT UNTIL 1
program faktorial;
uses wincrt;
var
i,n,f:integer;
begin
write('n = '); read(n);
i:=0;
f:=1;
repeat
i:=i+1;
f:=f*i;
until i=n;
writeln(n,' faktorial = ',f);
end.
C.PROGRAM REPEAT UNTL 2
Program Pengulangan;
Uses wincrt;
Var x:integer;
Begin
x:=1;
repeat
writeln(x,'. RICKY SEPRIYANTO adalah Seorang Mahasiswa Prodi TI/A5');
x:=x+1;
until x>9;
end
uses wincrt;
label back;
var
k,awal,akhir:integer;
rata,jum:real;
begin
back:
clrscr;
write('nilai awal = ');readln(awal);
write('nilai akhir = ');readln(akhir);
if awal<=akhir then
begin
repeat
jum:=jum+awal;
awal:=awal+2;
k:=k+1;
until awal>akhir;
end
else goto back;
rata:=jum/k;
writeln('rata-rata= ',rata:2:2);
write('================================================================================');
writeln(' ==*RICKYSEPRIYANTO_13010241*==');
writeln(' ==================================');
end.
B. PROGRAM REPEAT UNTIL 1
program faktorial;
uses wincrt;
var
i,n,f:integer;
begin
write('n = '); read(n);
i:=0;
f:=1;
repeat
i:=i+1;
f:=f*i;
until i=n;
writeln(n,' faktorial = ',f);
end.
C.PROGRAM REPEAT UNTL 2
Program Pengulangan;
Uses wincrt;
Var x:integer;
Begin
x:=1;
repeat
writeln(x,'. RICKY SEPRIYANTO adalah Seorang Mahasiswa Prodi TI/A5');
x:=x+1;
until x>9;
end
Subscribe to:
Posts (Atom)