VB题目,要用穷举法的....求代码
有1分,2分,5分硬币若干枚,从中取出20枚硬币使其总值为60分。求出有多少种取法以及每一种取法的1分,2分,5分硬币个数...
有1分,2分,5分硬币若干枚,从中取出20枚硬币使其总值为60分。求出有多少种取法以及每一种取法的1分,2分,5分硬币个数
展开
1个回答
展开全部
用一个listbox计数。。下面是代码
Private Sub Form_Load()
For five = 0 To 12
For two = 0 To 30
If (60 - five * 5 - two * 2) >= 0 Then
List1.AddItem ("五分:" & five & " 两分:" & two & " 一分:" & (60 - five * 5 - two * 2))
End If
Next
Next
MsgBox List1.ListCount
End Sub
Private Sub Form_Load()
For five = 0 To 12
For two = 0 To 30
If (60 - five * 5 - two * 2) >= 0 Then
List1.AddItem ("五分:" & five & " 两分:" & two & " 一分:" & (60 - five * 5 - two * 2))
End If
Next
Next
MsgBox List1.ListCount
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询