用vb.net 程序求 世界数学史上的百鸡问题
操作方法
- 01
设每只公鸡卖5块钱,每只母鸡卖3块钱,每3只小鸡卖1块钱。现在要用100块钱买一百只鸡,求能买到公鸡、母鸡、小鸡各是多少只? 提示:设能买到公鸡x只,母鸡y只、小鸡z只,则: 5x+3y+1/3z=100 x+y+z=100 3个未知数,2个表达式,无法解出未知数。 只能使用穷举法。Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x, y, z As Integer For x = 1 To 20 For y = 1 To 33 z = 100 - x - y If (5 * x + 3 * y + z / 3 = 100) Then TextBox1.Text = "公鸡的只数" & "x =" & CStr(x) TextBox2.Text = "母鸡的只数" & "y= " & CStr(y) TextBox3.Text = "小鸡的只数" & "z= " & CStr(z)MsgBox("公鸡的只数:" & x & " " & "母鸡的只数:" & y & " " & "小鸡的只数:" & z) End If Next Next End SubEnd Class
赞 (0)