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

2025-01-01 15:16:39
推荐回答(2个)
回答1:

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。

回答2:

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