利用vb解决鸡兔同笼问题,总数有m只鸡和兔,鸡和兔的总脚数是n只,求鸡和兔各有多少只?

2024-12-26 15:21:24
推荐回答(2个)
回答1:

Private Sub Command1_Click()
Dim m, n
m = Val(InputBox(请输入总头数))
n = Val(InputBox(请输入种脚数))
Print "鸡", "兔"
For i = 1 To m
For j = 1 To m
If i * 2 + j * 4 = n And i + j = m Then Print i, j
Next j
Next i
End Sub

回答2:

设鸡为X只,鸭Y只,则:X+Y=M,2X+4Y=N就可以求出了