Rabu, 09 Desember 2009

Tugas Pemrograman Komputer 1

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array_1;
Uses Wincrt;
Var
a,b:integer;
tabel: array[1..3,1..2] of integer;
Begin
Write('Tabel 1,1:');Readln(tabel[1,1]);
Write('Tabel 1,2:');Readln(tabel[1,2]);
Write('Tabel 2,1:');Readln(tabel[2,1]);
Write('Tabel 2,2:');Readln(tabel[2,2]);
Write('Tabel 3,1:');Readln(tabel[3,1]);
Write('Tabel 3,2:');Readln(tabel[3,2]);
Writeln;
Clrscr;
For a:=1 to 3 do
Begin
For b:=1 to 2 do
Write(tabel[a,b],' ');
Writeln;
End;
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array_2;
Uses Wincrt;
Var
b,k:integer;
tabel: array[1..3,1..3] of integer;
Begin
Write('Berapa baris matrik yang diinginkan? ');Readln(b);
Write('Berapa kolom matrik yang diinginkan? ');Readln(k);
Begin
For b:=1 to b do
Begin
For k:=1 to k do
Begin
Write('Tabel ',b,',',k,':');Readln(tabel[b,k]);
End;
End;
Clrscr;
For b:=1 to b do
Begin
For k:=1 to k do
Write(tabel[b,k],' ');
Writeln;
End;
End;
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array_3;
Uses Wincrt;
Var
b,c,k:integer;
tabel1: array[1..10,1..10] of integer;
tabel2: array[1..10,1..10] of integer;
tabel3: array[1..10,1..10] of integer;
Begin
Write('Baris matrik 1? ');Readln(b);
Write('Kolom matrik 1 = Baris matrik 2? ');Readln(c);
Write('Kolom matrik 2? ');Readln(k);
Begin
Writeln('Matrik 1');
For b:=1 to b do
Begin
For c:=1 to c do
Begin
Write('Tabel ',b,',',c,':');Readln(tabel1[b,c]);
End;
End;
Writeln;
Writeln('Matrik 2');
For c:=1 to c do
Begin
For k:=1 to k do
Begin
Write('Tabel ',c,',',k,':');Readln(tabel2[c,k]);
End;
End;
Clrscr;
For b:=1 to b do
Begin
For c:=1 to c do
Write(tabel1[b,c],' ');
Writeln;
End;
Writeln;
For c:=1 to c do
Begin
For k:=1 to k do
Write(tabel2[c,k],' ');
Writeln;
End;
End;
Writeln;
Begin
For b:=1 to b do
For k:=1 to k do
For c:=1 to c do
tabel3[b,k]:=(tabel3[b,k])+((tabel1[b,c])*(tabel2[c,k]));
End;
Begin
For b:=1 to b do
Begin
For k:=1 to k do
Write((tabel3[b,k]),' ');
Writeln;
End;
End;
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array_4;
Uses Wincrt;
Var
b,k:integer;
tabel1: array[1..10,1..10] of integer;
tabel2: array[1..10,1..10] of integer;
tabel3: array[1..10,1..10] of integer;
Begin
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;
Begin
For b:=1 to b do
Begin
For k:=1 to k do
Write(tabel3[b,k],' ');
Writeln;
End;
End;
End;
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array;
Uses Wincrt;
Var
a,b:integer;
data: array[1..10] of integer;
Begin
Write('Masukkan jumlah data yang diinginkan: ');Readln(b);
Begin
For a:=1 to b do
Begin
Write('Data ke-',a,':');Readln(data[a]);
writeln;
End;
End;
Clrscr;
For a:=1 to b do
Begin
Writeln('Data ke-',a,':',data[a]);
Writeln;
End;
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array;
Uses Wincrt;
Var
a,b,c:integer;
data: array[1..10] of integer;
Begin
Write('Masukkan jumlah data yang diinginkan: ');Readln(b);
Begin
For a:=1 to b do
Begin
Write('Data ke-',a,':');Readln(data[a]);
writeln;
End;
End;
Clrscr;
Write('Data ke berapa yang diinginkan? ');Readln(c);
Writeln('Data ke-',c,':',data[c]);
End.

Bagi teman-teman yang sedang belajar Pascal, bisa melihat contoh berikut ini tentang array.

Program Latihan_Array_Nilai_Maks_Min_Rata_Rata;
Uses Wincrt;
Var
a,b,c,maks,min:integer;
d:real;
data: array[1..10] of integer;
Begin
Write('Masukkan jumlah data yang diinginkan: ');Readln(b);
Begin
For a:=1 to b do
Begin
Write('Data ke-',a,':');Readln(data[a]);
Writeln;
End;
End;
Clrscr;
Begin
For a:=1 to b do
Begin
Writeln('Data ke-',a,':',data[a]);
Writeln;
End;
End;
Begin
c:=0;
For a:=1 to b do
Begin
c:=c+data[a];
End;
d:=c/b;
Writeln('Rata-rata data adalah ',(d):5:2);
End;
Begin
maks:=data[1];
For a:=2 to b do
Begin
If data[a]>maks then
maks:=data[a];
End;
Writeln('Data terbesar adalah ',(maks));
End;
Begin
min:=data[1];
For a:=2 to b do
Begin
If data[a] min:=data[a];
End;
Writeln('Data terkecil adalah ',(min));
End;
End.

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Buy Printable Coupons