ge=0
shi=0
bai=0
?"100~999以内的水仙花数是:"
for
i=100
to
999
ge=i%10
shi=int(i/10)%10
bai=int(i/100)
if
ge^3+shi^3+bai^3=i
?
i
endif
next
然后,直接点击感叹号,保存并运行,图:
CLEARaccept
"请输入第一个随机的三位数:"
to
x1
accept
"请输入第二个随机的三位数:"
to
x2
s=0
&&统计水仙花数
t1=MIN(x1,x2)
t2=MAX(x1,x2)
t="在"+t1+"和"+t2+"之间的水仙花数有:"
FOR
a=1
TO
9
FOR
b=0
TO
9
FOR
c=
0
to
9
x=a*100+b*10+c
IF
x=a^3+b^3+c^3
IF
x>=VAL(t1)
AND
x<=VAL(t2)
s=s+1
t=t+STR(x)
ENDIF
ENDIF
ENDFOR
ENDFOR
ENDFOR
?"在"+t1+"和"+t2+"之间的水仙花数有:"+STR(s)+"个"
?t
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)