Sabtu, 19 Desember 2009

Kumpulan Soal-Soal

H.KUMPULAN SOAL-SOAL
1.RUMUS KUADRAT
program rumus;
uses wincrt;
var x1,x2,a,b,c,d:real;
begin
write('masukkan nilai a=');readln(a);
write('masukkan nilai b=');readln(b);
write('masukkan nilai c=');readln(c);
if a=0 then write('error')else
begin
d:=(b*b)-(4*a*c);
writeln('D=',d:0:2);
if d>0 then
begin
writeln('pers.kuadrat memp.2 akar yg berbeda');
x1:=(-b+sqrt(d))/2*a;
x2:=(-b-sqrt(d))/2*a;
writeln('x1=',x1:0:2);
writeln('x2=',x2:0:2);
end
else
if d=0 then
begin
writeln('pers.kuadrat memp.akar yg sama');
x1:=-b/(2*a);
x2:=x1;
write('jadi x1 dan x2 adalah=',x2:0:2);
end
else
writeln('tdk memp akar real');
end;


end.
2.BILANGAN GANJIL
program bilangan_ganjil;
uses wincrt;
var
x,y,jum:integer;
begin
write('sampai berapa?');readln(y);
begin
x:=1;
repeat
write(x,' ');
x:=x+2;
until
x>y;
end;
end.
3.BILANGAN GENAP
program bilangan_genap;
uses wincrt;
var
x,y,jum:integer;
begin
write('sampai berapa?');readln(y);
begin
x:=2;
repeat
write(x,' ');
x:=x+2;
until
x>y;
end;
end.
4.BILANGAN GENAP DAN GANJIL
program bilangan_genap_dan_ganjil;
uses wincrt;
var x,y,n:integer;
begin
write('masukkan bilangan=');readln(n);
for x:=1 to n do
if x mod 2=0 then write(x:3);writeln(' bilangan genap');
for y:=1 to n do
if y mod 2<>0 then write(y:3);write(' bilangan ganjil');
end.
5.SEGITIGA ASYIK
program segitiga;
uses wincrt;
var x,y,z:integer;
begin
write('masukkan angka segitiga asyik=');readln(y);
for x:=1 to y do
begin
for z:=1 to x do
write(x:3);
writeln;
end;
end.
6.JUMLAH SEGITIGA ASYIK
program segitiga;
uses wincrt;
var n,i,j,a:integer;
begin
write('masukkan angka untuk segitiga asyik=');readln(n);
for j:=1 to n do
begin
for i:=1 to j do
if j<=i then write(j:2,' = ')else
write(j:2,' + ');
for i:=1 to j do
a:=i*j;
write(a);
writeln;
end;
end.
7.SEGITIGA 15
program segitiga;
uses wincrt;
var x,y,z:integer;
begin
write('masukkan angka=');readln(y);
for x:=1 to y do
begin
for z:=1 to x do
write(' ',15);
writeln;
end;
end.
8.SEGITIGA TERBALIK
program segitiga5;
uses wincrt;
var x,y,z:integer;
begin
write('masukkan angka untuk segitiga=');readln(y);
for x:=y downto 1 do
begin
for z:=x downto 1 do
write(' ',5);
writeln;
end;
end.
9.MEMILIH HARI
program hari;
uses wincrt;
var x:integer;
begin
write('pilih hari ke-');readln(x);
case x of
1:begin
clrscr;
writeln('minggu');
end;
2:begin
clrscr;
writeln('senin');
end;
3:begin
clrscr;
writeln('selasa');
end;
4:begin
clrscr;
writeln('rabu');
end;
5:begin
clrscr;
writeln('kamis');
end;
6:begin
clrscr;
writeln('jumat');
end;
7:begin
clrscr;
writeln('sabtu');
end;
end;
end.

10.MENENTUKAN TANGGAL SETELAH TANGGAL KELAHIRAN
program tanggal;
uses wincrt;
var a,b,c,d,e,f,h,i,g,j,k,n,x,y,z:integer;
begin
write('msukkan tanggal lahir=');readln(x,y,z);
write('masukkan berapa hari setelah tanggal kelahiran=');readln(n);
h:=n div 360;
i:=n mod 360;
j:=i div 30;
k:=i mod 30;
writeln('umurnya=',h:2,' tahun',j:2,' bulan ',k:2,' hari');
f:=(x+k) mod 30;
e:=(y+j) mod 12;
g:=z+h;

writeln('tanggal sekarang= tanggal ',f,' bulan ',e,' tahun ',g);
end.
11.MENENTUKAN NILAI MAKSIMUM DARI TIGA ANGKA
program maks;
uses wincrt;
var x,y,z:integer;
begin
write('masukkan angka=');readln(x);
write('masukkan angka=');readln(y);
write('masukkan angka=');readln(z);
begin
if (x>y) and (x>z) then write(x)else
if (y>x) and (y>z) then write(y)else
if (z>x) and (z>y) then write(z);
end;
end.
12.ABJAD (VOKAL DAN KONSONAN)
program abjad;
uses wincrt;
var x:string;
begin
write('masukkan huruf=');readln(x);

if (x='a') or (x='i') or (x='u') or (x='e') or (x='o') then write('vokal')
else
write('konsonan');

end.
13.BILANGAN PRIMA
program bilangan_prima;
uses wincrt;
var i,n,j:integer;
prima:boolean;
begin
write('masukkan bilangan=');read(n);
clrscr;
for i:=1 to n do
begin
prima:=true;
if i=1 then prima:=false
else
begin
for j:=2 to (i div 2) do
begin
if(i mod j=0) then prima:=false;
end;
if prima then write(i,' ');
end;
end;
end.
14.ARRAY (PENJUMLAHAN MATRIKS)
Program penjumlahan_matriks;
Uses Wincrt;
Var
b,k:integer;

Write('Baris matrik 1 = Baris matrik 2? ');Readln(b);
Write('Kolom matrik 1 = Kolom matrik 2? ');Readln(k);
Begin
Writeln('Matrik 1');
For b:=1 to b do
Begin
For k:=1 to k do
Begin
Write('Tabel ',b,',',k,':');Readln(tabel1[b,k]);
End;
End;
Writeln;
Writeln('Matrik 2');
For b:=1 to b do
Begin
For k:=1 to k do
Begin
Write('Tabel ',b,',',k,':');Readln(tabel2[b,k]);
End;
End;
Clrscr;
For b:=1 to b do
Begin
For k:=1 to k do
Write(tabel1[b,k],' ');
Writeln;
End;
Writeln;
For b:=1 to b do
Begin
For k:=1 to k do
Write(tabel2[b,k],' ');
Writeln;
End;
Writeln;
Begin
For b:=1 to b do
Begin
For k:=1 to k do
tabel3[b,k]:=tabel1[b,k]+tabel2[b,k];
End;
End;
writeln('hasilnya adalah=');
Begin
For b:=1 to b do
Begin
For k:=1 to k do
Write(tabel3[b,k],' ');
Writeln;
End;
End;
End;
End.
15.ARRAY (PERKALIAN MATRIKS)
program perkalian_matrik;
uses wincrt;
var
a,b,c:array [1..25,1..25] of real;
i,j,k,m,n,l:byte;
begin
writeln('PERKALIAN MATRIKS');
write('baris matriks pertama=');readln(m);
write('kolom matriks pertama/brs matriks kedua=');readln(n);
write('kolom matriks kedua=');readln(l);
writeln;
writeln('komponen matriks yang pertama');
for i:=1 to m do
begin
for j:=1 to n do
begin
write('nilai[',i,',',j,']=');readln(a[i,j]);
end;
writeln;
end;
writeln('komponen matriks kedua');
for i:=1 to n do
begin
for j:=1 to l do
begin
write('nilai[',i,',',j,']=');readln(b[i,j]);
end;
writeln;
end;
for i:=1 to m do
begin
for j:=1 to l do
begin
c[i,j]:=0;
for k:=1 to l do
c[i,j]:=c[i,j]+a[i,k]*b[k,j];
end;
end;
writeln;
writeln('hasil perkalian matriks');
writeln;
for i:=1 to m do
begin
writeln;
for j:=1 to l do
write(c[i,j]:5:2);
end;
end.

16.FUNGSI
program fungsi_x;
uses wincrt;
var
x:integer;
function fungsi (x:real):real;
var
y:real;
begin
write('masukkan nilai x=');readln(x);
y:=x*x+8*x+10;
fungsi:=y;
end;
begin
clrscr;
writeln('hasil dari nilai y nya adalah=',fungsi(x):2:0);

end.
17.REKURSI
program re;
uses wincrt;
var akhir:word;
procedure rekursi;
begin
if akhir<10 then
begin
write(' rochmah ');
akhir:=akhir+1;
rekursi;
end;
end;
begin
akhir:=0;
rekursi;
end.
17.FAKTORIAL
program fak;
uses wincrt;
procedure faktorial(n : byte;var hasil:longint);
begin
if n<=1 then
hasil:=1
else
begin
faktorial(n-1,hasil);
hasil:=n*hasil;
end;
end;

var
n:byte;
f:longint;
begin
write('berapa faktorial?');readln(n);
faktorial(n,f);
writeln('faktorial=',f);
end.

18.PROGRAM FUNGSI TUKAR(yg ditukar hanya nilai A dan B)
Program Tukar;
uses wincrt;
FUNCTION Tukar_nilai(a,b,c:integer):integer;
var
temp:integer;
begin
temp:=A;
A:=C;
C:=temp;

writeln('a:',a);
writeln('b:',b);
writeln('c:',c);
end;

var a,b,c:integer;
begin
a:=100;
b:=200;
c:=300;
writeln('Nilai sebelum ditukar');
writeln('A:',a);
writeln('B:',b);
writeln('C:',c);
writeln('nilai sesudah ditukar');
Tukar_nilai(a,b,c);
end.

19. ARRAY(nilai mahasiswa)


uses wincrt;

var nim:array[1..20] of string[10];

no:array[1..20] of integer;

nama:array[1..20] of string[25];

nilai:array[1..20] of integer;

i,n:integer;

begin

write(‘masukkan data yang diperlukan =’ );read(n);

clrscr;

for i:=1 to n do

begin

write(‘NO = ‘);readln(no[i]);

write(‘NIM = ‘); readln(nim[i]);

write(‘NAMA = ‘); readln(nama[i]);

write(‘NILAI = ‘); readln(nilai[i]);

clrscr;

end;

gotoxy(25,1);write(‘DAFTAR NILAI MAHASISWA’);

gotoxy(30,2);writeln(‘SEMESTER III’);

writeln;

writeln(‘===============================================================’);

writeln(‘| NO | NIM | NAMA | NILAI |’);

writeln(‘===============================================================’);

for i:=1 to n do

begin

writeln(no[i]:4,nim[i]:17,nama[i]:19,nilai[i]:21);

end;

readln;

end.

20.PERKALIAN BERULANG


program perkalian_berulang;

uses wincrt;

var a,b,c:integer;

function faktorial(n:integer):longint;

begin

if n=0 then faktorial:=1

else

faktorial:=n*faktorial(n-1);

end;

begin

write(‘a=’);read(a);

writeln;

for b:=1 to (a-1) do write(b,’*');

write(a,’=',faktorial(a));

end.

21. PENGURANGAN MATRIKS


program pengurangan_matriks;

uses wincrt;

var

a,b,c:array[1..25,1..25] of real;

d,e,f,i,j,k:byte;

begin

clrscr;

gotoxy(30,1);writeln(‘===========================’);

gotoxy(30,2);writeln(‘”Program Pengurangan Matriks”‘);

gotoxy(30,3);writeln(‘===========================’);

writeln;

write(‘jumlah baris= ‘);readln(d);

write(‘jumlah kolom= ‘);readln(e);

writeln;

writeln(‘matrik yang pertama’);

for i:=1 to d do

begin

for j:=1 to e do

begin

write(‘nilai[',i,',',j,']?’);readln(a[i,j]);

end;

writeln;

end;

writeln(‘matrik yang kedua’);

for i:=1 to d do

begin

for j:=1 to e do

begin

write(‘nilai[',i,',',j,']?’);readln(b[i,j]);

end;

writeln;

end;

for i:=1 to d do

begin

for j:=1 to e do

begin

c[i,j]:=a[i,j]-b[i,j];

end;

end;

clrscr;

writeln(‘matrik yang pertama’);

for i:=1 to d do

begin

write(‘|’);

for j:=1 to e do

begin

write(a[i,j]:9:2);

end;

write(‘|’);

writeln;

end;

writeln;

writeln(‘matrik yang kedua’);

for i:=1 to d do

begin

write(‘|’);

for j:=1 to e do

begin

write(b[i,j]:9:2);

end;

write(‘|’);

writeln;

end;

writeln;

writeln(‘hasil dari pengurangan matrik : ‘);

writeln;

for i:=1 to d do

begin

write(‘|’);

for j:=1 to e do

write(c[i,j]:9:2);

write(‘|’);

writeln;

end;

end.

22. BELAH KETUPAT


program belah_ketupat;

uses wincrt;

var

baris,kolom,jumbaris:integer;

begin

writeln(‘PROGARM BELAH KETUPAT’);

writeln(‘———————’);

writeln;

write(‘jumlah baris : ‘);

readln(jumbaris);

writeln;

baris :=1;

while baris <= jumbaris-1 do

begin

write(‘*’: jumbaris+1-baris);

kolom:=2;

while kolom <= (2*baris-1) do

begin

write(‘*’);

kolom :=kolom+1;

end;

writeln;

baris:=baris+1;

end;

baris :=jumbaris;

while baris >= 1 do

begin

write(‘*’:jumbaris+1-baris);

kolom:=2*baris-1;

while kolom >= 2 do

begin

write(‘*’);

kolom :=kolom-1;

end;

writeln;

baris:=baris-1;

end;

end.

23. SEGITIGA ASYIK 1


program segitiga_asyik_1;

uses wincrt;

var

baris,kolom,jumbaris:integer;

begin

writeln(‘PROGRAM SEGITIGA ASYIK 1′);

writeln(‘————————’);

writeln;

write(‘jumlah baris : ‘);

readln(jumbaris);

writeln;

baris :=jumbaris;

while baris >= 1 do

begin

write(‘*’: jumbaris+1-baris);

kolom:=2*baris-1;

while kolom >= 2 do

begin

write(‘*’);

kolom :=kolom-1;

end;

writeln;

baris:=baris-1;

end;

end.

24. SEGITIGA ASYIK 2

program segitiga_asyik_2;

uses wincrt;

var

a,b,c:integer;

begin

writeln(‘PROGRAM SEGITIGA ASYIK 3′);

writeln(‘————————’);

writeln;

write(‘ n=’);read(a);

writeln;

for b:=1 to a-1 do

begin

for c:=1 to b do write(‘*’:2);

writeln;

end;

for b:=a downto 1 do

begin

for c:=b downto 1 do write(‘*’:2);

writeln;

end;

end.

Tidak ada komentar:

Posting Komentar