编程vb题 编程显示100–500之间所有水仙花数,并求出它们的和(水仙花是3位数,其各位数的立方
答案:2 悬赏:20 手机版
解决时间 2021-03-24 12:50
- 提问者网友:山高云阔
- 2021-03-23 16:32
编程vb题 编程显示100–500之间所有水仙花数,并求出它们的和(水仙花是3位数,其各位数的立方
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-03-23 17:56
Private Sub Form_Click()
Dim s As Integer
Cls
Print "所求水仙花数为:";
For i = 100 To 500
If i = (i Mod 10) ^ 3 + ((i Mod 100) 10) ^ 3 + (i 100) ^ 3 Then
s = s + i
Print i;
End If
Next i
Print
Print "它们的和为:" & s
End Sub追问
这个也不懂,高手追答Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim flag As Boolean
If KeyAscii = 13 Then
flag = False
For i = 0 To Combo1.ListCount - 1
If Combo1.Text = Combo1.List(i) Then
flag = True
Exit For
End If
Next i
If flag = False Then
Combo1.AddItem Combo1.Text
End If
End If
End Sub追问谢谢你
Dim s As Integer
Cls
Print "所求水仙花数为:";
For i = 100 To 500
If i = (i Mod 10) ^ 3 + ((i Mod 100) 10) ^ 3 + (i 100) ^ 3 Then
s = s + i
Print i;
End If
Next i
Print "它们的和为:" & s
End Sub追问
这个也不懂,高手追答Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim flag As Boolean
If KeyAscii = 13 Then
flag = False
For i = 0 To Combo1.ListCount - 1
If Combo1.Text = Combo1.List(i) Then
flag = True
Exit For
End If
Next i
If flag = False Then
Combo1.AddItem Combo1.Text
End If
End If
End Sub追问谢谢你
全部回答
- 1楼网友:拜訪者
- 2021-03-23 19:05
Private Sub Command1_Click()
Dim i As Integer, s As Integer
Dim sum As Integer
Dim a As Integer, b As Integer, c As Integer
Print "100到500所有水仙花数(也叫梅花数):";
For i = 100 To 500
a = i 100 '取百位数
b = i 10 Mod 10 '或 b = i Mod 100 10 取十位数
c = i Mod 10 ‘取个位数
s = a ^ 3 + b ^ 3 + c ^ 3 '水仙花数的判断依据
If s = i Then
Print i;
sum = sum +i
End If
Next i
Print "和为:" & sum
End Sub
Dim i As Integer, s As Integer
Dim sum As Integer
Dim a As Integer, b As Integer, c As Integer
Print "100到500所有水仙花数(也叫梅花数):";
For i = 100 To 500
a = i 100 '取百位数
b = i 10 Mod 10 '或 b = i Mod 100 10 取十位数
c = i Mod 10 ‘取个位数
s = a ^ 3 + b ^ 3 + c ^ 3 '水仙花数的判断依据
If s = i Then
Print i;
sum = sum +i
End If
Next i
Print "和为:" & sum
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯