你得有个范围,数字无上限,水仙花数也无上限,vb不可能算出二十位,三十位name大的水仙花数
这个是算3位数的水仙花数
Private Sub Command1_Click()
Dim n As Integer, a As Integer, b As Integer, c As Integer
For i = 100 To 999 Step 1
a = i \ 100
b = (i - 100 a) \ 10
c = i - 100 a - 10 b
If a ^ 3 + b ^ 3 + c ^ 3 = i Then
Print i;
n = n + 1
If n Mod 2 = 0 Then
End If
End If
Next i
End Sub
Private Sub Command1_Click()
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
If a a a + b b b + c c c = 100 a + 10 b + c Then Print a & "^3+" & b & "^3+" & c & "^3=" & a a a & "+" & b b b & "+" & c c c & "="; a & b & c
Next c, b, a
End Sub
这个是打印所有三位数的水仙花数的代码:
Private Sub Command1_Click()
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
If a 100 + b 10 + c = a ^ 3 + b ^ 3 + c ^ 3 Then
print a 100 + b 10 + c
End If
Next
Next
Next
End Sub
Private Sub Form_Click()
Dim s As Integer
Cls
Print "所求水仙花数为:";
For i = 100 To 500
If i = (i Mod 10) ^ 3 + ((i Mod 100) \ 10) ^ 3 + (i \ 100) ^ 3 Then
s = s + i
Print i;
End If
Next i
Print "它们的和为:" & s
End Sub
Private Sub Command1_Click()
Dim i%, j%, k%,
Do While i <10
Do While j <10
Do While k <10
If i ^ 3 + j^ 3 + k ^ 3 = i100+j10+k 1 Then Text1Text = Text1Text & " " & i & j & k
k=k+1
Loop
j=j+1
Loop
i=i+1
Loop
End Sub
以上就是关于VB题:在窗体上以每行两个数的格式输出所有的“水仙花数。全部的内容,包括:VB题:在窗体上以每行两个数的格式输出所有的“水仙花数。、VB程序写水仙花数、如何用vb语言编写水仙花数的代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)