Option ExplicitPrivate Sub Command1_Click() Dim i As Integer, a As Integer, b As Integer, c As Integer i = 100 For i = 100 To 999 a = i / 100 b = (i / 10) Mod 10 c = (i Mod 10) Mod 10 If i = a * a * a + b * b * b + c * c * c Then Print i end if '这里要补上 Next i End Sub
Option ExplicitPrivate Sub Command1_Click() Dim i As Integer, a As Integer, b As Integer, c As Integer i = 100 For i = 100 To 999 a = i / 100 b = (i / 10) Mod 10 c = (i Mod 10) Mod 10 If i = a * a * a + b * b * b + c * c * c Then Print i Next i End Sub
我的是这样 是求所有三位的水仙花数是吧?Private Sub Command1_Click() Dim i As Integer, g As Integer, s As Integer, b As Integer For i = 100 To 999 g = Mid(i, 3, 1) s = Mid(i, 2, 1) b = Mid(i, 1, 1) If i = g ^ 3 + s ^ 3 + b ^ 3 Then Print i Else End If Next End Sub
Dim i As Integer, a As Integer, b As Integer, c As Integer
i = 100
For i = 100 To 999
a = i / 100
b = (i / 10) Mod 10
c = (i Mod 10) Mod 10
If i = a * a * a + b * b * b + c * c * c Then
Print i
end if '这里要补上
Next i
End Sub
Option ExplicitPrivate Sub Command1_Click()
Dim i As Integer, a As Integer, b As Integer, c As Integer
i = 100
For i = 100 To 999
a = i / 100
b = (i / 10) Mod 10
c = (i Mod 10) Mod 10
If i = a * a * a + b * b * b + c * c * c Then Print i
Next i
End Sub
Dim i As Integer, g As Integer, s As Integer, b As Integer For i = 100 To 999
g = Mid(i, 3, 1)
s = Mid(i, 2, 1)
b = Mid(i, 1, 1)
If i = g ^ 3 + s ^ 3 + b ^ 3 Then
Print i
Else
End If
Next
End Sub
返回 Variant (String),其中包含字符串中指定数量的字符。语法Mid(string, start[, length])Mid 函数的语法具有下面的命名参数:部分 说明
string 必要参数。字符串表达式,从中返回字符。如果 string 包含 Null,将返回 Null。
start 必要参数。为 Long。string 中被取出部分的字符位置。如果 start 超过 string 的字符数,Mid 返回零长度字符串 ("")。
length 可选参数;为 Variant (Long)。要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到尾端的所有字符。
说明欲知 string 的字符数,可用 Len 函数。注意 MidB 函数作用于字符串中包含的字节数据,如同在双字节字符集(DBCS)语言中一样。因此其参数指定的是字节数,而不是字符数。对于使用 MidB的示例代码,请参阅示例主题中的第二个示例。