Var i,d,n: integer;
a: array[1..20] of integer;
t: real;
Begin
t:=0; d:=0;
For i:=1 to 20 do
Begin
Write('a[',i,']='); readln(a[i]);
End;
For i:=1 to 20 do
Begin
If a[i]>0 then t:=t+a[i];
d:=d+1;
End;
Write('Trung binh cong cac phan tu nguyen duong la :',t/d:0:5);
Readln
End.
em đang cần lắm ạ, em cảm ơn trước ạ
uses crt;
var a:array[1..20]of integer;
dem,t:integer;
begin
clrscr;
for i:=1 to 20 do
begin
write('a[',i,']='); readln(a[i]);
end;
{------------------------------------------------}
dem:=0;
t:=0;
for i:=1 to 20 do
if a[i]>0 then
begin
t:=t+a[i];
inc(dem);
end;
writeln('trung binh cong cac so duong la: ',t/dem:4:2);
readln;
end.
uses crt;
var tong,i,n: longint;
a: array[1..20] of integer;
begin
clrscr; tong:= 0; n:= 0;
for i:= 1 to 20 do
begin
write('Nhap phan tu thu ',i,': ');
readln(a[i]);
if a[i] > 0 then
begin
tong:= tong + a[i];
n:= n + 1;
end;
end;
write('TBC cac phan tu nguyen duong la: ',tong/n:0:2);
readln
end.