关于PASCAL语言的问题2

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:27:08
编写程序输出3到100之间的全部素数之和

调试通过的程序如下:

program exp;
function ok(x:integer):boolean;
var i:integer;
begin
ok:=true;
for i:=2 to x-1 do
if x mod i=0 then ok:=false;
end;

var i,s:integer;
begin
s:=0;
for i:=3 to 100 do
if ok(i) then s:=s+i;
writeln(s);
end.

运行输出的结果是:
1058