...如果是质数则输出yes 否则输出no 用break语句
发布网友
发布时间:2024-05-29 13:54
我来回答
共3个回答
热心网友
时间:2024-06-12 01:27
program t1;
var
n,i:longint;
f:boolean;
begin
readln(n);
i:=2;f:=true;
while (i<=trunc(sqrt(n))) and f do
if n mod i=0 then f:=false
else inc(i);
if f then writeln('Yes')
else writeln('No');
readln;readln;{看输出的}
end.
不知回答是否合意,如有问题请指出,本人感激不尽!
热心网友
时间:2024-06-12 01:32
var n,i,j,k:longint;
t:boolean;
begin
readln(n);
if n=1 then begin
writelN('no');
halt;
end;
t:=true;
for i:=2 to trunc(sqrt(n)) do if n mod i=0 then begin
t:=false;
break;
end;
if t then writeln('yes') else writeln('no');
end.
热心网友
时间:2024-06-12 01:31
program Project1;
var
i,t:word;
n:integer;
begin
readln(n);
for i:=2 to (n-1) do
if n mod i=0 then begin
inc(t);break;end;
if t=0 then writeln('Yes')
else writeln('no');
readln;
end.