uses crt;
var a:array[1..100]of integer;
i,n,t,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cac so vua nhap la: ',t);
if t>=2 then
begin
kt:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt:=1;
break;
end;
if kt=0 then writeln(t,' la so nguyen to')
else writeln(t,' khong la so nguyen to');
end
else writeln(t,' khong la so nguyen to');
readln;
end.
Bài tham khảo từ anh Thịnh
uses crt;
var a:array[1..100]of integer;
i,n,t,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cac so vua nhap la: ',t);
if t>=2 then
begin
kt:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt:=1;
break;
end;
if kt=0 then writeln(t,' la so nguyen to')
else writeln(t,' khong la so nguyen to');
end
else writeln(t,' khong la so nguyen to');
readln;
end.