用VFP编写程序找出 1000 以内的所有完数,并按下面格式输出:6 its factors are 1,2,3

来源:百度知道 编辑:UC知道 时间:2024/05/24 20:31:01

LOCAL i,j,k,strTemp

for i=1 to 1000
k=0
strTemp=""
for j=1 to i-1
if i % j=0
k=k+j
strTemp = Strtemp + alltrim(str(j))+","
endif
endfor
if k=i
?str(i) +" its factors are :" +left(strTemp,len(strtemp)-1)
endif
endfor

调试通过的程序代码如下:

dimension f(1000)

for i=1 to 1000

  k=1

  s=0

  for j=1 to i-1

    if mod(i,j)=0 then

      f(k)=j

      s=s+j

      k=k+1

    endif

  endfor

  if i=s then

&