鸡兔同笼
已知在同一笼子里有鸡和兔的总头数为m头,鸡和兔的总脚数为n只,求鸡和兔各有多少只?
左上角的Label是显示的,对应控件依次是
txtTotal 总数
txtFeet 脚数
Command1 计算
Command2 生成
Option Explicit Private Sub Command1_Click() Dim s As Long,j As Long Dim x As Integer,y As Integer s = CLng(txtTotal.Text) j = CLng(txtFeet.Text) 's = x + y 'j = 2 * x + 4 * y y = j / 2 - s x = s - y lblResult.Caption = "计算结果:" & vbCrLf & "鸡有 " & CStr(x) & "只" & vbCrLf & "兔有 " & CStr(y) & "只" End Sub Private Sub Command2_Click() Dim x As Integer,y As Integer x = Int(Rnd * 100): y = 100 - x txtTotal.Text = CStr(x + y) txtFeet.Text = CStr(2 * x + 4 * y) End Sub Private Sub Form_Load() Command2_Click End Sub
这是最简单不过的二元一次方程求解了
给最新最新最新最新最新最新最新,比处女还新的新手