- 13
- 0
- 约小于1千字
- 约 2页
- 2023-11-28 发布于上海
- 举报
编制程序解决”百鸡问题”
方法一编写程序解决百钱买百鸡问题:公鸡5元/只,母鸡3元/只,小鸡一元买3只,用100元买100 只鸡,问有哪些购买方案?
方法一
Private Sub Command1_Click() Dim a, b, c As Integer
Private Sub Command1_Click() Dim a, b, c As Integer
Dim aconst, bconst As Integer Dim sum As Integer
aconst = Int((100 - (100 / 3)) / 5) + 1 For a = 0 To aconst
bconst = Int((100 - a * 5) / 3) + 1 For b = 0 To bconst
c = 100 - a - b
If Not (c Mod 3) Then sum = a * 5 + 3 * b + c / 3 If sum = 100 Then
Print 公鸡 a, 母鸡 b, 小鸡 c ElseIf sum 100 Then
Exit For End If End If Next Next
End Sub
方法二
Private Sub Command1_Click()
Private Sub Command1_Click()
Dim Cock, Hen, Chi
原创力文档

文档评论(0)