Private Sub Form_Load()
Dim a As Integer, b As Integer, c As Integer, d As Integer
Print "水仙花数为:";
For a = 0 To 9
For b = 0 To 9
For c = 0 To 9
For d = 0 To 9
If a ^ 3 + b ^ 3 + c ^ 3 + d ^ 3 = a * 1000 + b * 100 + c * 10 + d Then
Print a * 1000 + b * 100 + c * 10 + d;
End If
Next d
Next c
Next b
Next a
Rem 第二种方法求水仙花数
Print
Print "水仙花数为:";
For i = 0 To 10000
a = i \ 1000
b = (i - a * 1000) \ 100
c = (i - a * 1000 - b * 100) \ 10
d = i - a * 1000 - b * 100 - c * 10
If i = a ^ 3 + b ^ 3 + c ^ 3 + d ^ 3 Then
Print i;
End If
Next i
End Sub