如何用vb语言编写水仙花数的代码?
3个回答
展开全部
for i=1 to 9
for j=0 to 9
for k=0 to 9
if i^3+j^3+k^3=100*i+10*j+k then
msgbox 100*i+10*j+k
end if
next
next
next
不会再追问
for j=0 to 9
for k=0 to 9
if i^3+j^3+k^3=100*i+10*j+k then
msgbox 100*i+10*j+k
end if
next
next
next
不会再追问
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
判断法
Dim a() As Integer
n = InputBox("请输入一个n位正整数" & Chr(10) & "n大于等于3", "水仙花数", 153)
Dim i As Integer
m = Len(n)
ReDim a(1 To m) As Integer
For i = 1 To m
a(i) = Val(Mid(n, i, 1))
Next i
For i = 1 To m
s = a(i) ^ m + s
Next i
If s = Val(n) Then
MsgBox "是水仙花数"
Else
MsgBox "不是水仙花数"
End If
Dim a() As Integer
n = InputBox("请输入一个n位正整数" & Chr(10) & "n大于等于3", "水仙花数", 153)
Dim i As Integer
m = Len(n)
ReDim a(1 To m) As Integer
For i = 1 To m
a(i) = Val(Mid(n, i, 1))
Next i
For i = 1 To m
s = a(i) ^ m + s
Next i
If s = Val(n) Then
MsgBox "是水仙花数"
Else
MsgBox "不是水仙花数"
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询