作业帮 > 数学 > 作业

vb 中1元的钞票换成一分 二分 五分 每个至少8个 几种方案

来源:学生作业帮 编辑:大师作文网作业帮 分类:数学作业 时间:2024/11/11 21:44:50
vb 中1元的钞票换成一分 二分 五分 每个至少8个 几种方案
vb 中1元的钞票换成一分 二分 五分 每个至少8个 几种方案
Private Sub Command1_Click()
Dim Yuan As Long
Dim Fen1 As Long
Dim Fen2 As Long
Dim Fen5 As Long
Dim ZongFen As Long
Dim FangAn As Long
Dim Min As Long
Dim i As Long, j As Long, k As Long
Yuan = 1 * 100 '一元等于100分
Fen1 = 1
Fen2 = 2
Fen5 = 5
Min = 8 '每个面值最少8张
ZongFen = Yuan - Fen1 * Min - Fen2 * Min - Fen5 * Min '减除每个面值最少8张总分数
For i = 0 To Fix(ZongFen / Fen5) '循环组合
For j = 0 To Fix((ZongFen - Fen5 * i) / Fen2)
If ZongFen - Fen2 * j - Fen5 * i >= 0 Then
ZongFen = ZongFen - Fen2 * j - Fen5 * i
FangAn = FangAn + 1
List1.AddItem ZongFen + Min & "张一分 + " & j + Min & "张二分 + " & i + Min & "张五分 = " & ZongFen + Min + (j + Min) * Fen2 + (i + Min) * Fen5 & "分"
ZongFen = Yuan - Fen1 * Min - Fen2 * Min - Fen5 * Min
End If
Next
Next
MsgBox FangAn & "个方案!"
End Su