不考虑速度的话
For index As Integer = 100 To 999
Dim o_int百位 As Integer = Math.Pow(Val(index.ToString()(0)), 3)
Dim o_int十位 As Integer = Math.Pow(Val(index.ToString()(1)), 3)
Dim o_int个位 As Integer = Math.Pow(Val(index.ToString()(2)), 3)
If o_int百位 + o_int十位 + o_int个位 = index Then
Console.WriteLine(index)
End If
Next
这道题我非做不可!因为我很讨厌带有中文的变量,如上:"o_int个位"
(抱歉).
sub main()
dim int1 as integer=100
dim intxp1,intxp2,intxp3 as integer
dim str1 as string
do while int1<=999
str1=cstr(int1)
intxp1=cint(mid(str1,1,1)) '截取字符,转换变量类型
intxp2=cint(mid(str1,2,1))
intxp3=cint(mid(str1,3,1))
if (intxp1^3+intxp2^3+intxp3^3)=int1 then
system.console.writeline(int1)
end if
int1+=1
loop
system.console.readline() '只用来查看结果
end sub
不考虑速度的话
For index As Integer = 100 To 999
Dim o_int百位 As Integer = Math.Pow(Val(index.ToString()(0)), 3)
Dim o_int十位 As Integer = Math.Pow(Val(index.ToString()(1)), 3)
Dim o_int个位 As Integer = Math.Pow(Val(index.ToString()(2)), 3)
If o_int百位 + o_int十位 + o_int个位 = index Then
Console.WriteLine(index)
End If
Next