uses crt; Var i,n: integer; Begin Clrscr; Write (‘Nhap so can kiem tra n: ‘); readln(n); If (n=0) or (n=1) then Writeln(n,’ Khong phai la so nguyen to’) Else Begin i:=1; Repeat i:= i+1; Until (n mod i= 0) or (i*i>n); If i*i>n then Writeln (n,’ la so nguyen to’) Else Writeln (n,’ khong phai la so nguyen to’); End; Readln; End.
mình nghĩ lớp 11 làm đang học function nên mình làm function nha
program kiemtra;
uses crt;
var n:integer;
function ktnt(k:integer):boolean;
var i:integer;
begin
ktnt:=false;
if k<2 then exit; {neu <2 thi thoat va lay gia tri false}
for i:=2 to trunc(sqrt(k)) do
if k mod i=0 then exit; {neu chia het cho 1 so thi thoat va lay gia tri false}
ktnt:=true; {lay ket qua dung khi thoa man cac dieu kien tren}
end;
BEGIN
clrscr;
write(‘Nhap n: ‘); readln(n);
write(ktnt(n));
readln
end.
uses crt;
Var i,n: integer;
Begin
Clrscr;
Write (‘Nhap so can kiem tra n: ‘); readln(n);
If (n=0) or (n=1) then
Writeln(n,’ Khong phai la so nguyen to’)
Else
Begin
i:=1;
Repeat
i:= i+1;
Until (n mod i= 0) or (i*i>n);
If i*i>n then
Writeln (n,’ la so nguyen to’)
Else
Writeln (n,’ khong phai la so nguyen to’);
End;
Readln;
End.