回答这题目还需要先去百度“水仙花数”
亲测可用,如上
Private Sub Command1_Click()
Dim i, j, m, n, sum As Integer
Dim arr(1000) As Integer
Dim a, s As Integer
a = 1
For n = 100 To 999
i = n \ 100
j = (n Mod 100) \ 10
m = n Mod 10
If i ^ 3 + j ^ 3 + m ^ 3 = n Then
sum = sum + n
arr(a) = n
a = a + 1
End If
Next n
Text1.Text = sum
Print "100-999间水仙花数有:"
For s = 1 To a - 1
Print arr(s);
If s Mod 5 = 0 Then Print
Next s
End Sub
Private Sub Command1_Click()
For i = 100 To 999
If (i Mod 10) ^ 3 + (i \ 10 Mod 10) ^ 3 + (i \ 100) ^ 3 = i Then
Print i;
s = s + i
End If
Next i
Print "Sum="; s
End Sub