用pascal语言求100以内的质数program oo;vari,j:integer;f:boolean;beginfor i:=1 to 100 dobeginf:=true;for j:=2 to trunc(sqrt(i))+1 doif i mod j=0 then begin f:=false;end;if f=true thenwrite(i:4);end;readln;end.for j:=2 to trunc(sqrt(i))+1 do截

来源:学生作业帮助网 编辑:六六作业网 时间:2024/05/09 23:44:12
用pascal语言求100以内的质数programoo;vari,j:integer;f:boolean;beginfori:=1to100dobeginf:=true;forj:=2totrunc(

用pascal语言求100以内的质数program oo;vari,j:integer;f:boolean;beginfor i:=1 to 100 dobeginf:=true;for j:=2 to trunc(sqrt(i))+1 doif i mod j=0 then begin f:=false;end;if f=true thenwrite(i:4);end;readln;end.for j:=2 to trunc(sqrt(i))+1 do截
用pascal语言求100以内的质数
program oo;
var
i,j:integer;
f:boolean;
begin
for i:=1 to 100 do
begin
f:=true;
for j:=2 to trunc(sqrt(i))+1 do
if i mod j=0 then begin f:=false;end;
if f=true then
write(i:4);
end;
readln;
end.
for j:=2 to trunc(sqrt(i))+1 do
截尾函数后为什么要加1?

用pascal语言求100以内的质数program oo;vari,j:integer;f:boolean;beginfor i:=1 to 100 dobeginf:=true;for j:=2 to trunc(sqrt(i))+1 doif i mod j=0 then begin f:=false;end;if f=true thenwrite(i:4);end;readln;end.for j:=2 to trunc(sqrt(i))+1 do截
其实加与不加一个样子
不信你可以试验一下
但是我建议的是不加
因为很多大的程序要对数字判奇偶
上万个数字判断
如果每个数字都要多加一次判断
没用
而且还浪费时间
这是我的看法
如果有不同的
绝不否认!