VB实验 寻求程序

来源:百度知道 编辑:UC知道 时间:2024/05/18 06:55:39
一个n位的正整数,其各位数的n次方之和等于这个数,称这个数为Armstrong数。列如,153=1^3+5^3+3^3.
试编写程序求所有的二位,三位,四位的Armstrong数。
用过程调用实现上述功能。
哪位高人帮帮忙?

VB6.0版——只需要在窗体上设置一个按钮:
Private Sub Command1_Click()
Dim a(4) As Double, i As Double, b As Double
For i = 9 To 9999
b = 0
For j = 1 To Len(CStr(i))
a(j) = CDbl(Mid(CStr(i), j, 1))
b = b + a(j) ^ Len(CStr(i))

Next
If i = b Then Print i
Next
End Sub

VBS版,2位的这种数字不存在

for a=1 to 9
for b=1 to 9
for c=1 to 9
if a^3+b^3+c^3=int(a&b&c) then
t=t&chr(10)&a&b&c
end if
for d=1 to 9
if a^4+b^4+c^4+d^4=int(a&b&c&d) then
t=t&chr(10)&a&b&c&d
end if
next
next
next
next
msgbox(t)