作业帮 > 综合 > 作业

用pascal求a 到b 之间的最大质数

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/06 01:26:35
用pascal求a 到b 之间的最大质数
我的程序是求出A到B之间的所有质数后,再求出他们的个数.再怎么求a 到b 之间的最大质数?program sushu;
var
i,j,t,a,b:integer;
f:boolean;
begin
readln(a,b);
if a=1 then a:=a+1;
for i:= a to b do
begin
f:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then f:=false;
if f=true then
begin
write(i:4);
inc(t);
end;
end;
writeln;
writeln(t:4);
readln
end.
你可以在
if f=true then
begin
write(i:4);
inc(t);
end;
end;
这个循环中增加一个integer变量x来负责记录 目前为止最大的质数
即加入 x:=i