0 bình luận về “VCT kiểm tra xem n có phải là snt hay ko”
uses crt; var n,i: integer; ok: boolean; begin clrscr; write (‘nhap n: ‘); readln (n); ok:=false; if (n=0) or (n=1) or (n=3) then ok:=false else begin ok:=true; for i:=3 to n-1 do if n mod i=0 then ok:=false; end; if ok=false then writeln (n,’ ko phai la so nguyen to’); if ok=true then writeln (n,’ la so nguyen to’); readln; end.
uses crt;
var n,i: integer;
ok: boolean;
begin
clrscr;
write (‘nhap n: ‘); readln (n);
ok:=false;
if (n=0) or (n=1) or (n=3) then ok:=false
else
begin
ok:=true;
for i:=3 to n-1 do
if n mod i=0 then ok:=false;
end;
if ok=false then writeln (n,’ ko phai la so nguyen to’);
if ok=true then writeln (n,’ la so nguyen to’);
readln;
end.