Monday, November 21, 2011

menghitung jumlah, perkalian dan rata-rata dalam pascal


program ulang;

uses wincrt;

type a=array[1..10000] of longint;

var
T:a;
n,temp,temp2,i,j:longint;
c:real;

begin
i:=1;
repeat
write('masukan angka = ');read(n);
T[i]:=n;
i:=i+1;
until (n>9999);
clrscr;
temp:=T[1];
write('penjumlahan = ',T[1],'+');
for j:=2 to (i-2) do
begin
write(T[j]);
temp:=temp+T[j];
if (j<>(i-2)) then
write('+')
else
write('=');
end;
write(temp);
writeln;
temp2:=T[1];
write('perkalian   = ',T[1],'*');
for j:=2 to (i-2) do
begin
write(T[j]);
temp2:=temp2*T[j];
if (j<>(i-2)) then
write('*')
else
write('=');
end;
write(temp2);
writeln;
c:=(temp/(i-2));
writeln('rata-rata   = ',c:0:2);
end.

No comments:

Post a Comment