viết chương trình pascal kiểm tra xem n có phải là snt ko
ok: boolean
0 bình luận về “viết chương trình pascal kiểm tra xem n có phải là snt ko ok: boolean”
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:longint; scan:boolean; begin clrscr; write(‘Nhap n: ‘); readln(n); if n = 2 then scan:=true else for i:=2 to trunc(sqrt(n)) do if n mod i = 0 then scan:=false else scan:=true; if scan = true then writeln(n,’ la so nguyen to’) else writeln(n,’ khong phai 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.
uses crt;
var n,i:longint;
scan:boolean;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
if n = 2 then scan:=true
else
for i:=2 to trunc(sqrt(n)) do
if n mod i = 0 then scan:=false else scan:=true;
if scan = true then writeln(n,’ la so nguyen to’)
else writeln(n,’ khong phai la so nguyen to’);
readln;
end.