program hotrotinhoc ;
var a: array[1..32000] of integer ;
tg,j,i,n,tong,tich,tong1,tich1 : integer ;
begin
write('n='); readln(n);
writeln('nhap gia tri cua cac phan tu');
for i:= 1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('day so vua nhap vao la :',a[i],' ');
writeln;
write('Cac so nguyen duong la :');
tong:=0; tich:=1; tong1:=0; tich1:=1;
for i:= 1 to n do
begin
tong:=tong+a[i];
tich:=tich*a[i];
if a[i] mod 2 <> 0 then tong1 := tong1+sqr(a[i]) ;
if a[i] mod 2=0 then tich1:=tich1*a[i];
if a[i] > 0 then write(a[i]);
end;
writeln;
writeln('Tong la :',tong);
writeln('Tich la :',tich);
writeln('Tong binh phuong cac so le la :',tong1);
write('Tich cac vi tri chan la :',tich1);
for i:= 1 to n-1 do
for j:= 1 to n do
if a[i] > a[j] then
begin
tg:=a[i];
a[i]:=a[j] ;
a[j]:=tg ;
end;
writeln('Mang sau khi da sap xep la :');
for i:= 1 to n do write(a[i]:6);
readln
end.
Tham khảo:
program hotrotinhoc ;
var a: array[1..32000] of integer ;
tg,j,i,n,tong,tich,tong1,tich1 : integer ;
begin
write('n='); readln(n);
writeln('nhap gia tri cua cac phan tu');
for i:= 1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('day so vua nhap vao la :',a[i],' ');
writeln;
write('Cac so nguyen duong la :');
tong:=0; tich:=1; tong1:=0; tich1:=1;
for i:= 1 to n do
begin
tong:=tong+a[i];
tich:=tich*a[i];
if a[i] mod 2 <> 0 then tong1 := tong1+sqr(a[i]) ;
if a[i] mod 2=0 then tich1:=tich1*a[i];
if a[i] > 0 then write(a[i]);
end;
writeln;
writeln('Tong la :',tong);
writeln('Tich la :',tich);
writeln('Tong binh phuong cac so le la :',tong1);
write('Tich cac vi tri chan la :',tich1);
for i:= 1 to n-1 do
for j:= 1 to n do
if a[i] > a[j] then
begin
tg:=a[i];
a[i]:=a[j] ;
a[j]:=tg ;
end;
writeln('Mang sau khi da sap xep la :');
for i:= 1 to n do write(a[i]:6);
readln
end.