計概老師出了道題目給我們...我是機械科的...竟然要我們作這個..有點難
題目意思是說...有X,Y,Z,3個數,X在1~9之間,Y跟Z在0~9之間..然後要寫出X的3次方+Y的3次方+Z的3次方=XYZ..
例如X=1,Y=1,Z=1..X的3次方+Y的3次方+Z的3次方=3..沒有111
這樣就不行..然後我也不知道該怎麼寫~\"~..
要能用VB作出..按按鈕後,它會跑出符合這條件的數字..請高手幫幫忙吧..
如果真的沒辦法,至少也請教教如何作出只要有數字跑出來就好了,老師說這樣也有分數..= =\"....
2006-06-18 17:12:51 · 2 個解答 · 發問者 翔 1 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim I As Integer, J As Integer, N As String, S As String, A As String For I = 100 To 999 N = 0: S = "": A = "" For J = 1 To 3 N = Val(N) + Mid(CStr(I), J, 1) ^ 3 A = A & Mid(CStr(I), J, 1) & "^3+" S = S & Mid(CStr(I), J, 1) Next If S = N Then Print Left(A, Len(A) - 1); "="; S NextEnd Sub
2006-06-18 19:33:07 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
Private Sub Form_Load()
Dim x As Integer, y As Integer, z As Integer
Dim sum1 As Integer, sum2 As Integer
For x = 1 To 9
For y = 0 To 9
For z = 0 To 9
sum1 = x ^ 3 + y ^ 3 + z ^ 3
sum2 = 100 * x + 10 * y + z
If sum1 = sum2 Then
Print "x="; x, "y="; y, "z="; z
Print
End If
Next z
Next y
Next x
End Sub
2006-06-18 19:29:28 · answer #2 · answered by puppy 5 · 0⤊ 0⤋