Jika ingin mencari nilai rata-rata menggunakan array pada pascal, maka cobalah codingan di bawah ini
Coding
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.
Output
These icons link to social bookmarking sites where readers can share and discover new web pages.
Posting Komentar