展开全部
你得有个范围,数字无上限,水仙花数也无上限,vb不可能算出二十位,三十位name大的水仙花数
这个是算3位数的水仙花数
Private Sub Command1_Click()
Dim n As Integer, a As Integer, b As Integer, c As Integer
For i = 100 To 999 Step 1
a = i \ 100
b = (i - 100 * a) \ 10
c = i - 100 * a - 10 * b
If a ^ 3 + b ^ 3 + c ^ 3 = i Then
Print i;
n = n + 1
If n Mod 2 = 0 Then
Print
End If
End If
Next i
End Sub
这个是算3位数的水仙花数
Private Sub Command1_Click()
Dim n As Integer, a As Integer, b As Integer, c As Integer
For i = 100 To 999 Step 1
a = i \ 100
b = (i - 100 * a) \ 10
c = i - 100 * a - 10 * b
If a ^ 3 + b ^ 3 + c ^ 3 = i Then
Print i;
n = n + 1
If n Mod 2 = 0 Then
End If
End If
Next i
End Sub
展开全部
代码如下:
Private Sub Command1_Click()
Dim i As Integer, t As Integer
t = 0
For i = 100 To 999
'个位的立方 + 十位的立方 + 百位的立方 = 该数本身
If (i Mod 10) ^ 3 + ((i \ 10) Mod 10) ^ 3 + (i \ 100) ^ 3 = i Then
If t = 0 Then
Print i;
t = 1
Else
Print i
t = 0
End If
End If
Next
End Sub
Private Sub Command1_Click()
Dim i As Integer, t As Integer
t = 0
For i = 100 To 999
'个位的立方 + 十位的立方 + 百位的立方 = 该数本身
If (i Mod 10) ^ 3 + ((i \ 10) Mod 10) ^ 3 + (i \ 100) ^ 3 = i Then
If t = 0 Then
Print i;
t = 1
Else
Print i
t = 0
End If
End If
Next
End Sub
追问
运行不出来。。。你的代码。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询