用VB编程,一百元钱,一元三只小鸡,三元一只母鸡,五元一只公鸡,求有几种方案及方案个数,要用三重循环

标签:公鸡三元

摘要:
你想买几只鸡??
追问一下,要买几只鸡??

不确定的话,有很多种方案啊

Private Sub Command1_Click()
Dim xiao As Integer, mu As Integer, gong As Integer
Dim i As Integer
For xiao = 0 To 300
For mu = 0 To 33
For gong = 0 To 20
If xiao / 3 + mu * 3 + gong * 5 = 100 Then
i = i + 1
Print "方案" & i & "你可以用一百块购买" & xiao & "只小鸡," & mu & "只母鸡," & gong & "只公鸡"
End If
Next gong
Next mu
Next xiao
Print "总计共有" & i & "种方案"
End Sub

其他答案

Private Sub Form_Click()
Dim g, m, x As Integer
For g = 0 To 20
For m = 0 To 33
For x = 0 To 100
If g + m + x = 100 And g * 5 + m * 3 + x / 3 = 100 Then
List1.AddItem "公鸡" & g & "母鸡" & m & "小鸡" & x
End If
Next x
Next m
Next g
End Sub
在窗体上加一个列表框 名为 list1
谢谢,可以了不?

其他答案

Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, n As Integer
For i = 1 To 300
If i Mod 3 = 0 Then
For j = 1 To 33
For k = 1 To 20
If i \ 3 + 3 * j + 5 * k = 100 Then
Debug.Print "xj:" & i, "mj:" & j, "gj:" & k
n = n + 1
End If
Next k
DoEvents
Next j
End If
Next i
Debug.Print "FA:" & n
End Sub

其他答案

如果说是三次循环一样的是4的4次方