找素数 pascal

2024-12-04 21:37:56
推荐回答(1个)
回答(1):

var
n,i:integer;
a:array[1..1000] of longint;

function zhisu(n:longint):boolean;
var
j,k:longint;
findd:boolean;
begin
k:=trunc(sqrt(n));
if n=1 then zhisu:=false
else if (n=2)or(n=3) then zhisu:=true
else begin
findd:=false;
j:=1;
repeat
j:=j+1;
if (n mod j)=0 then findd:=true;
until findd or (j>k);
zhisu:=not findd;
end;
end;

begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do if zhisu(a[i]) then write(a[i]:0,' ');
end.