编一VB程序,显示出所有的水仙花数。

2025-01-03 00:35:17
推荐回答(1个)
回答1:

Dim i%, j%, m%
s = i * 100 + j * 10 * m '一定=0
Do While s > 0 '一定不成立
'"水仙花数"
Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百)
For a = 0 To 9
For b = 0 To 9
For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then
MsgBox 100 * c + 10 * b + a
End If
Next c
Next b
Next a
End Sub

'''''''''''''''''''''''
Private Sub Form_Click()
Dim i%, j%, m%, n%

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
Print n; "="; i; "^3+"; j; "^3+"; m; "^3"
End If
Next n

End Sub