俺是刚学的,想了好久,就是不知道该怎么算,应该是一个多重循环的问题,请高手帮忙解答,
先谢了!
写错了,小鸡是3只一钱!!!
看了一个冒泡排序的例子,研究了差不多3个小时在看懂,从中得了一点启发,
---------------------------------------------------------------------
Private Sub Command1_Click()
Dim g, m, x, a As Integer
For g = 1 To 16
For m = 1 To 31
For x = 3 To 96 Step 3
If g + m + x = 100 And 5 * g + 3 * m + x / 3 = 100 Then
Print g; m; x
End If
Next x
Next m
Next g
End Sub
----------------------------------------------------------------------
4,18,78 结果
8,11,81
12,4,84
------------------
这么个问题花了我4个多小时,哎。。
看了一个冒泡排序的例子,研究了差不多3个小时在看懂,从中得了一点启发,
---------------------------------------------------------------------
Private Sub Command1_Click()
Dim g, m, x, a As Integer
For g = 1 To 16
For m = 1 To 31
For x = 3 To 96 Step 3
If g + m + x = 100 And 5 * g + 3 * m + x / 3 = 100 Then
Print g; m; x
End If
Next x
Next m
Next g
End Sub
----------------------------------------------------------------------
4,18,78 结果
8,11,81
12,4,84
------------------
这么个问题花了我4个多小时,哎。。
虽然这个想起来很简单,但效率太低了,不知道你学过矩阵没,用矩阵解决快得多,不过代码也就不可能就这么点了.
Dim x As Integer
Dim y As Integer
Dim z As Integer
Private Sub Form_Load()
For x = 1 To 20
For y = 1 To 35
If (15 * x + 9 * y + (100 - x - y)) = 300 Then Debug.Print x, y, 100 - x - y
Next
Next
End Sub