Mảng 1 chiều:
Program HOC24;
var a: array[1..32000] of integer;
i,n: integer;
t: longint;
begin
write('Nhap so phan tu: '); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do if a[i]>0 then t:=t+a[i];
write('Tong cac phan tu duong la: ',t);
readln
end.
Mảng 2 chiều:
Program HOC24;
var a: array[1..100,1..100] of integer;
i,n,m,j: integer;
t: longint;
begin
write('Nhap so hanh va so cot: '); readln(n,m);
for i:=1 to m do
for j:=1 to n do
begin
write('a[',i,'',j,']='); readln(a[i,j]);
end;
t:=0;
for i:=1 to m do
for j:=1 to n do
if a[i,j]>0 then t:=t+a[i,j];
write('Tong cac phan tu duong la: ',t);
readln
end.