program MangSoChinhPhuong;
const
MaxSize = 100;
type
Mang = array[1..MaxSize] of Integer;
procedure NhapMang(var arr: Mang; var n: Integer);
var
i: Integer;
begin
repeat
Write('Nhap so luong phan tu (5 < n < 100): ');
Readln(n);
until (n > 5) and (n < 100);
Writeln('Nhap mang ', n, ' phan tu:');
for i := 1 to n do
begin
Write('Phan tu ', i, ': ');
Readln(arr[i]);
end;
end;
function LaSoChinhPhuong(num: Integer): Boolean;
begin
LaSoChinhPhuong := (Trunc(Sqrt(num)) * Trunc(Sqrt(num))) = num;
end;
procedure InCacSoChinhPhuong(arr: Mang; n: Integer);
var
i: Integer;
begin
Writeln('Cac so chinh phuong trong mang:');
for i := 1 to n do
begin
if LaSoChinhPhuong(arr[i]) then
Write(arr[i], ' ');
end;
Writeln;
end;
function TinhTongSoChinhPhuong(arr: Mang; n: Integer): Integer;
var
i: Integer;
begin
TinhTongSoChinhPhuong := 0;
for i := 1 to n do
begin
if LaSoChinhPhuong(arr[i]) then
TinhTongSoChinhPhuong := TinhTongSoChinhPhuong + arr[i];
end;
end;
function SoChinhPhuongLonNhat(arr: Mang; n: Integer): Integer;
var
i, maxChinhPhuong: Integer;
begin
maxChinhPhuong := 0;
for i := 1 to n do
begin
if LaSoChinhPhuong(arr[i]) and (arr[i] > maxChinhPhuong) then
maxChinhPhuong := arr[i];
end;
SoChinhPhuongLonNhat := maxChinhPhuong;
end;
var
mangSo: Mang;
kichThuoc, tong, maxChinhPhuong: Integer;
begin
NhapMang(mangSo, kichThuoc);
InCacSoChinhPhuong(mangSo, kichThuoc);
tong := TinhTongSoChinhPhuong(mangSo, kichThuoc);
Writeln('Tong cac so chinh phuong trong mang la: ', tong);
maxChinhPhuong := SoChinhPhuongLonNhat(mangSo, kichThuoc);
Writeln('So chinh phuong lon nhat trong mang la: ', maxChinhPhuong);
Readln;
end.