Anda di halaman 1dari 3

uses crt;

var
n,i,total:integer;
b:array[1..100] of integer;
rata:real;
begin
total:=0;
clrscr;
writeln('##################################################');
writeln('# #');
writeln('# Program mencari nilai rata-rata #');
writeln('# #');
writeln('##################################################');
writeln;
write('masukan banyak bilangan = '); readln(n);
for i:= 1 to n do begin
write('masukkan bilangan ke-',a,' = ');readln(b[n]);
total:=total+b[n];
end;
rata:=total / n;
writeln;
writeln('jumlah bilangan = ' ,total);
writeln('rata-rata bilangan = ',rata:0:2);
readln;
end.

program array_1dimensi;
uses crt;
var
tugas,mid,final : array[1..10] of integer;
rata : array[1..10] of real;
i,byk : byte;
tambah : char;
label input;
begin
input:
write('Masukan banyaknya data :');readln(byk);
for i:=1 to byk do
begin
write('Nilai tugas :');
readln(tugas[i]);
write('Nilai Mid :');
readln(mid[i]);
write('Nilai Final :');
readln(final[i]);
rata[i]:=(tugas[i]+mid[i]+final[i])/3;
end;
clrscr;
for i:=1 to byk do
begin
writeln('-----------------------------------');
writeln('| No. | Nilai | Rata |');
writeln('| |---------------------| |');
writeln('| | Tugas | Mid | Final | |');
writeln('-----------------------------------');
for i:=1 to byk do
begin
write('|',i,'|',tugas[i],'|',mid[i],'|',final[i],'|,rata[i]:2:2,'|');
readln;
end;
writeln('-----------------------------------');
write('Ingin input data nilai lagi [Y/T]?');readln(tambah);
if (tambah='Y') or (tambah='y') then
goto input;
readln;
end;
clrscr;
end.

Output dari listing diatas adalah sebagai berikut :