PS:本回复只针对最后一题人民币求解题!
测试了下 wang_yingjian 的代码,好像啥结果也没有(题目中貌似没有三元面值的人民币吧?!):
抽空又写了一个,经测试,可以推出各种取法及每种取法中的每种面值的钞票张数。
Private Sub Form_Load()
EnumerateRMB
Unload Me
End Sub
Sub EnumerateRMB()
Dim intNumberOfRMB1 As Integer ' 1 元人民币的张数.
Dim intNumberOfRMB2 As Integer ' 2 元人民币的张数.
Dim intNumberOfRMB5 As Integer ' 5 元人民币的张数.
Dim intCounter As Integer ' 取法计数器.
intCounter = 0
' /* 枚举 5 元人民币的张数. */
For intNumberOfRMB5 = 1 To 100 / 5
' /* 枚举 2 元人民币的张数. */
For intNumberOfRMB2 = 1 To 100 / 2
' 获取 1 元人民币的张数.
intNumberOfRMB1 = 100 - intNumberOfRMB5 * 5 - intNumberOfRMB2 * 2
' 如果 1 元人民币的张数不为负数且三种面值的人民币张数之和为 30.
If (intNumberOfRMB1 >= 0) And (intNumberOfRMB1 + intNumberOfRMB2 + intNumberOfRMB5 = 30) Then
intCounter = intCounter + 1
MsgBox "第 " & CStr(intCounter) & " 种取法:" & vbCrLf & _
"1 元取 " & CStr(intNumberOfRMB1) & " 张" & vbCrLf & _
"2 元取 " & CStr(intNumberOfRMB2) & " 张" & vbCrLf & _
"5 元取 " & CStr(intNumberOfRMB5) & " 张", vbOKOnly, "取法"
End If
Next
Next
End Sub
其运行效果如图所示:
CACCB FTFFF 程序片段在哪里? 程序语句在哪里?
dim a as integer,b as integer,c as integer,d as integer
c = 30 - a - b
for a = 1 to 30
for b = 1 to 30
if a * 1 + b * 2 + c * 5 = 100 and a + b + c = 30 then
pring "一元" + a + "张,二元" + b + "张,三元" + c + "张"
d = d + 1
end if
next b
next a
print "一共有" + d + "种方法"