用vb.net程序求鸡兔同笼问题
孙子算经》中就记载的问题: “今有鸡兔同笼,上有三十五头,下有九十四足,问鸡兔各几何?”
求解鸡兔同笼问题,设一个笼子中有鸡x只,兔y只,每只鸡2条腿,每只兔4条腿,鸡和兔总头数h,总脚数f。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim h As Integer = TextBox1.Text
Dim f As Integer = TextBox2.Text
Dim x As Integer = (4 * h - f) / 2
Dim y As Integer = (f - 2 * h) / 2
TextBox3.Text = x
TextBox4.Text = y
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox4.Text = ""
TextBox3.Text = ""
End SubEnd Class
赞 (0)