Program pascal menentukan nilai total,maksimal,minimum dan
rata.
uses crt;
var n, bilangan : integer;
nilai, total, maksimal, minimal,rata:real;
begin
total:=0;
write('jumlah
bilangan :');readln(bilangan);
writeln;
for n:=1 to bilangan
do
begin
write ('nilai
bilangan ke ',n,' : ');readln(nilai);
total := total +
nilai;
if n =1 then
begin
maksimal := nilai;
minimal := nilai;
end
else
begin
if nilai >
maksimal then maksimal := nilai
else begin
if nilai <
minimal then minimal := nilai
end;
end;
end;
rata := total /
bilangan;
writeln;
writeln ('nilai
tertinggi : ', maksimal :1:2);
writeln ('nilai
terendah : ', minimal :1:2);
writeln
('rata-rata : ', rata :1:2);
writeln
('total : ', total :1:2);
readkey;
end.
output :
0 komentar:
Posting Komentar