program olah_array (ke-4 --> menentukan index nilai max dan min versi ke-2)

program olah_array;
uses wincrt;
var i,n, total,min,max, indexma,indexmi: integer; rata2: real;
nilai: array [1..10] of integer;
begin
total:= 0;
readln (n);
for i:= 1 to n do
begin
write ('Nilai Ke-',i, ':');
readln (nilai[i]);
total:=(nilai[i]);
total:= total+nilai[i];
end;
rata2:= total/n;
writeln ('rata-rata nilai: ', rata2:4:2);

min:= nilai[1];
for i:=2 to n do
begin
if min>nilai[i] then begin
min:=nilai[i] ; indexmi:=i ;
end
else begin
min:= min; indexmi:=1;
end;

max:= -9999;
for i:=1 to n do
begin
if max max:= nilai[i]; indexma:=i; end;
end;
writeln('Nilai Tertinggi: ', max,' di index ke-', indexma);
writeln('Nilai Terendah: ', min,' di index ke-', indexmi);
end;
end.

No comments:

Post a Comment