pascal补全大括号内的程序:输出1~1000之间的质数,并求出这些质数的和
varn,i,sum:integer;{};beginsum:=2;write(2,'');forn:=3to999doif{}thenbeginflag:=true;i...
var n,i,sum:integer;{ };
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { } then
begin
flag:=true; i:=2;
while flag and { } do
begin
if { } then flag:=false;
i:=i+1;
end;
if { } then begin write(n,' ');{ };end;
end;
writeln;
writeln('sum=',sum);
end. 展开
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { } then
begin
flag:=true; i:=2;
while flag and { } do
begin
if { } then flag:=false;
i:=i+1;
end;
if { } then begin write(n,' ');{ };end;
end;
writeln;
writeln('sum=',sum);
end. 展开
3个回答
展开全部
var n,i,sum:integer;{flag:boolean};//宣告
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { (n mod 2)=1 } then //当n为奇数时,执行
begin
flag:=true; i:=2;
while flag and {i<n} do //循环的条件
begin
if {(n mod i=0)} then flag:=false;//如果n被i除余0那麼n不为质数;
i:=i+1;
end;
if {flag} then begin write(n,' ');{inc(sum,n)};end; //如果n为质数,那麼印出n的值并累加sum;
end;
writeln;
writeln('sum=',sum);
end.
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { (n mod 2)=1 } then //当n为奇数时,执行
begin
flag:=true; i:=2;
while flag and {i<n} do //循环的条件
begin
if {(n mod i=0)} then flag:=false;//如果n被i除余0那麼n不为质数;
i:=i+1;
end;
if {flag} then begin write(n,' ');{inc(sum,n)};end; //如果n为质数,那麼印出n的值并累加sum;
end;
writeln;
writeln('sum=',sum);
end.
展开全部
var n,i,sum:integer;{ flag: boolean };
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { odd(n) } then
begin
flag:=true; i:=2;
while flag and { i < n } do
begin
if { n mod i = 0 } then flag:=false;
i:=i+1;
end;
if { flag } then begin write(n,' ');{ sum:= sum + n };end;
end;
writeln;
writeln('sum=',sum);
end.
begin
sum:=2; write(2,' ');
for n:=3 to 999 do
if { odd(n) } then
begin
flag:=true; i:=2;
while flag and { i < n } do
begin
if { n mod i = 0 } then flag:=false;
i:=i+1;
end;
if { flag } then begin write(n,' ');{ sum:= sum + n };end;
end;
writeln;
writeln('sum=',sum);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for i:=3 to 1000 do
for j:=2 to i-1
for j:=2 to i-1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询