VB编程 把一张一元钞票,换成一分,二分和五分硬币,每种至少5枚,问有多少种方案?

Private Sub Command1_Click()
n = 0
If x >= 0 And y >= 0 And z >= 0 Then
If x + y * 2 + z * 5 = 60 Then
n = n + 1
End If
Print n
End If
End Sub
我的是这样运行出来是0但是答案是205诶。

第1个回答  2014-04-24
Private Sub Command1_Click()

Dim n%,x%,y%,z%
n = 0
For x=5 to 100
For y=5 to 50
For z=5 to 20
If x + y * 2 + z * 5 = 100 Then n=n+1
Next
Next
Next
Print n
End Sub

这样做,答案就是205。追问

请问下我错在哪啊?

追答

你错在没设置循环,程序运行一次就结束了,而这一次不符合IF条件,故结果为0.同时,1元等于100分。

第2个回答  2014-04-24
Dim i As Long, j As Long, k As Long, n As Long
n = 0
For i = 5 To 100
For j = 5 To 50
For k = 5 To 20
If i + j * 2 + k * 5 = 100 Then n = n + 1
Next k
Next j
Next i
MsgBox n本回答被提问者采纳
相似回答