Program SO_NGUYEN_TO; Uses crt; Var i,n: integer; Begin Clrscr;
textcolor (lightgreen+blink); Writeln(‘KIEM TRA SO NGUYEN TO:’);
textcolor (white); Writeln(‘———————————‘);
textcolor (lightyellow); Write (‘Nhap so can kiem tra n = ‘); readln(n);
textcolor (white); 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.
program bt;
var
n,dem,i:integer;
begin
write(‘Nhap so can kiem tra: ‘); readln(n);
dem:=0;
for i:=1 to n do if n mod i=0 then dem:=dem+1;
if dem=2 then write(n,’ la so nguyen to’) else write(n,’ khong la so nguyen to’);
readln;
end.
Bạn có thể cho for i:=2 to n-1 do if n mod i=0 then dem:=dem+1; if dem=0 then write(‘la so nguyen to’) else write(‘Khong la so nguyen to’);
#Chuc_ban_hoc_tot
Program SO_NGUYEN_TO;
Uses crt;
Var i,n: integer;
Begin
Clrscr;
textcolor (lightgreen+blink);
Writeln(‘KIEM TRA SO NGUYEN TO:’);
textcolor (white);
Writeln(‘———————————‘);
textcolor (lightyellow);
Write (‘Nhap so can kiem tra n = ‘); readln(n);
textcolor (white);
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.
chúc bạn học tốt