求助
pascal吧
全部回复
仅看楼主
level 3
ww903611353 楼主

请编程,分别输出1000以内所有素数各位数字之和。如:<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"></?xml:namespace>
2: 2
3: 3
4: 4
5: 5
7: 7
11: 2
……
2014年04月13日 06点04分 1
level 3
ww903611353 楼主
请把确切的过程发过来
谢谢!
2014年04月13日 06点04分 2
level 13
var n,i,j,sum:longint;
s:string;
function su(x:longint):boolean;
var i:longint;
begin
su:=true;
if (x=0) or (x=1) then exit(false);
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then exit(false);
end;
begin
n:=1000;
for i:=1 to n do
if su(i) then
begin
sum:=0;
str(i,s);
for j:=1 to length(s) do
inc(sum,ord(s[j])-ord('0'));
writeln(i,':',sum);
end;
end.
2014年04月13日 09点04分 3
1