编一VB程序,显示出所有的水仙花数。
如153是水仙花数,因为153=1^3+5^3+3^3利用一个单循环将一个三位数逐位分离后进行判断。如dowhiles>0s1=smod10s=s\10loopPriva...
如153是水仙花数,因为153=1^3+5^3+3^3
利用一个单循环将一个三位数逐位分离后进行判断。
如 do while s>0
s1=s mod 10
s=s \10
loop
Private Sub Form_Click()
Dim i%, j%, m%
s = i * 100 + j * 10 * m
Do While s > 0
s1 = s Mod 10
s = s \ 10
要用单循环,请不要用三重循环
Print s1;
If i ^ 3 + j ^ 3 + m ^ 3 = i * 100 + j * 10 + m Then
Print Str(i * 100 + j * 10 + m)
End If
Loop
End Sub
有什么错误吗? 展开
利用一个单循环将一个三位数逐位分离后进行判断。
如 do while s>0
s1=s mod 10
s=s \10
loop
Private Sub Form_Click()
Dim i%, j%, m%
s = i * 100 + j * 10 * m
Do While s > 0
s1 = s Mod 10
s = s \ 10
要用单循环,请不要用三重循环
Print s1;
If i ^ 3 + j ^ 3 + m ^ 3 = i * 100 + j * 10 + m Then
Print Str(i * 100 + j * 10 + m)
End If
Loop
End Sub
有什么错误吗? 展开
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
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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询