2 câu trả lời
uses crt;
var a:array[1..250] of Integer;
i, n: byte;
function kt(x: Integer): boolean;
var j: word;
begin
if x<2 then exit(false);
for j:=2 to x-1 do if x mod j = 0
then exit(false);
exit(true);
end;
begin
clrscr;
write('nhap n = '); readln(n);
for i:=1 to n do
begin
write('nhap a[',i,'] = ');
readln(a[i]);
end;
writeln('cac so nguyen to: ');
for i:=1 to n do if kt(a[i])=true then
write(a[i], ' ');
readln;
end.
*Số không phải chữ số
uses crt;
var s,st:string;
i:byte;
so:longint;
function ktnt(k:longint):boolean;
var l:longint;
begin
ktnt:=false;
if k<2 then exit;
for l:=2 to trunc(sqrt(k)) do
if k mod l=0 then exit;
ktnt:=true;
end;
BEGIN
clrscr;
write('Nhap xau: '); readln(s);
i:=1;
while i<=length(s) do
begin
if s[i] in ['0'..'9'] then
begin
st:='';
while s[i] in ['0'..'9'] do
begin
st:=st+s[i];
i:=i+1;
end;
val(st,so);
if ktnt(so) then writeln(so);
end;
i:=i+1;
end;
readln;
end.
*Từng chứ số
uses crt;
var s,st:string;
i,so:byte;
function ktnt(k:longint):boolean;
var l:longint;
begin
ktnt:=false;
if k<2 then exit;
for l:=2 to trunc(sqrt(k)) do
if k mod l=0 then exit;
ktnt:=true;
end;
BEGIN
clrscr;
write('Nhap xau: '); readln(s);
for i:=1 to length(s) do
if s[i] in ['2'..'9'] then
begin
val(s[i],so);
if ktnt(so) then writeln(so);
end;
readln;
end.