hyqd.net
当前位置:首页 >> 百钱买百鸡vB求答案数 >>

百钱买百鸡vB求答案数

只有三个解.你和书本的内容有点出入.书中是:公鸡2元/只,母鸡3元/只,小鸡0.5元/只 dim a%, b%, c% for a = 0 to 20 for b = 0 to 33 c = 100 - a - b if a * 5 + b * 3 + c / 2 = 100 then print a, b, c next b next a end sub

百元买百鸡问题:一百个铜钱买了一百只鸡,其中公鸡一只5钱、母鸡一只3钱,小鸡一钱3只,问一百只鸡中公鸡、母鸡、小鸡各多少).这是一个古典数学问题,设一百只鸡中公鸡、母鸡、小鸡分别为x,y,z,问题化为三元一次方程组:这本来

给你一个最优化的代码:dim x,y,a for x=1 to 33 for y=1 to 100 if 3*x+1*y+(100-x-y)/3=100 then a=a&"3元鸡买"&x&"只"&" "&"1元鸡买"&y&"只"&" "&"1/3元鸡买"&(100-x-y)&"只"&vbcrlf end if next next msgbox(a)

i 要从0开始 private sub command1_click() for i = 0 to 20 for j = 0 to 33 z = 100 - j - i if 5 * i + 3 * j + 1 / 3 * z = 100 then print i, j, z next j next i end sub

Private Sub Command1_Click() '定义攻击、母鸡、小鸡的价格 a = 5 b = 3 c = (1 / 3) For i = 1 To 100 \ a For j = 1 To 100 \ b For k = 3 To 100 Step 3 If (a * i + b * j + c * k = 100) And (i + j + k = 100) Then Print "公鸡:" + Str(i) + "只、母鸡" + Str(j) + "只、小鸡" + Str(k) + "只" End If Next Next Next End Sub

Private Sub Command1_Click() dim x,y,z as integer For x = 1 To 100 For y = 1 To 100 z = 100 - x - y If 5 * x + 3 * y + z / 3 = 100 Then Print x, y, z End If Next y Next x End Sub

Private Sub Command1_Click() For i = 1 To 20 For j = 1 To 33 For k = 1 To 99 Step 2 If i * 5 + j * 3 + k / 3 = 100 Then Text1.Text = Text1.Text & "公鸡:" & i & "只" & "母鸡:" & j & "只" & "小

Option ExplicitConst a = 5, b = 3, c = 1Private Sub Form_Activate()Dim i As Integer, j As Integer, k As Integer, n As IntegerFor i = 1 To 100For j = 1 To 100For k = 1 To 100If i * a + j * b + k * c = 100 Thenn = n + 1List1.AddItem " 公鸡:" & i & " 母鸡:" & j & " 小鸡:" & kEnd IfNext: Next: NextMsgBox "共有组合:" & nEnd Sub

'由题可知:5*公+3*母+(100-公-母)/3=100 Dim g As Integer, m As Integer, x As Integer, s As String For g = 1 To 100 / 5 For m = 1 To 100 / 3 x = 100 - g - m If x Mod 3 = 0 Then If 5 * g + 3 * m + x / 3 = 100 Then s = s & "公鸡:" & g & " 母鸡:" & m & " 小鸡:" & x & Chr(13) & Chr(10) End If End If Next m Next g MsgBox s

网站首页 | 网站地图
All rights reserved Powered by www.hyqd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com