VB编程水仙花数
编程求出所有的水仙花数,并在窗体显示。所谓水仙花数,是指一个三位数,其各位数字的立方和等于该数本身。如153=1^3+5^3+3^3。程序界面自己设定。...
编程求出所有的水仙花数,并在窗体显示。所谓水仙花数,是指一个三位数,其各位数字的立方和等于该数本身。如153=1^3+5^3+3^3。程序界面自己设定。
展开
13个回答
展开全部
Private Sub Form_Click()
Dim q As Integer
Dim b As Integer
Dim s As Integer
Dim n As Integer
For n = 100 To 999
q = n \ 100
'求出百位数字
b = (n - q * 100) \ 10
'求出十位数字
s = n Mod 10
'求出个位数字
If ((q * q * q + b * b * b + s * s * s) = n) Then
Print n
End If
Next
End Sub
Dim q As Integer
Dim b As Integer
Dim s As Integer
Dim n As Integer
For n = 100 To 999
q = n \ 100
'求出百位数字
b = (n - q * 100) \ 10
'求出十位数字
s = n Mod 10
'求出个位数字
If ((q * q * q + b * b * b + s * s * s) = n) Then
Print n
End If
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2018-02-23
展开全部
Private Sub Form_Click()
For i = 100 To 999
z = CStr(i)
a = Val(Left(z, 1))
b = Val(Mid(z, 2, 1))
c = Val(Right(z, 1))
If a ^ 3 + b ^ 3 + c ^ 3 = i Then Print i
Next i
End Sub
For i = 100 To 999
z = CStr(i)
a = Val(Left(z, 1))
b = Val(Mid(z, 2, 1))
c = Val(Right(z, 1))
If a ^ 3 + b ^ 3 + c ^ 3 = i Then Print i
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-11
展开全部
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
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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-30
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private sub command1_click()
For a=0 to 9
For b=0 to 9
For c=0 to 9
If a^3+b^3+c^3=a*100+b*10+c then
Print a & b & c ,
End if
Next c
Next b
Next a
For a=0 to 9
For b=0 to 9
For c=0 to 9
If a^3+b^3+c^3=a*100+b*10+c then
Print a & b & c ,
End if
Next c
Next b
Next a
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询