公鸡5元一只,母鸡3元一只,小鸡1元三只,100元钱买100只鸡,问各买多少只?我编的东东为啥不行啊???或者哪位高手给个答案。
Dim a, b, c As Integer
For c = 3 To 100 Step 3
If (a + b + c = 100) And (5 * a + 3 * b + c / 3 = 100) Then
 Print a, b, c
End If
Next c

解决方案 »

  1.   

    Dim a As Integer, b As Integer, c As Integer
    for a=1 to 100
       for b=1 to 100
           For c = 1 To 100  
              If (a + b + c = 100) And (5 * a + 3 * b + c / 3 = 100) Then
                   Print a, b, c
               End If
    Next c,b,a
      

  2.   

    Dim a As Integer, b As Integer, c As Integer
    for a=1 to 100
       for b=1 to 100
           c=100-a-b
              if 5 * a + 3 * b + c / 3 = 100 Then
                   Print a, b, c
               End If
    Next b,a
      

  3.   

    楼主的错误在于只遍历了c,而没有遍历a与b,故没有考虑所有可能,a,b始终为0 ^-^
      

  4.   

    dim a as integer ,b as integer ,c as integer
    for a =0 to 100 
        for b =0 to 100
            for c =0 to 100
                if 5*a+3*b+c=100 and a+b+c=100 then print a ;b;c
            next
        next
    next
    print的输出结果是0 0 100
    另外楼主的第一个错误是申明变量时就已经错了。 
      

  5.   

    明白了,太谢谢大家了,我一定好好学,为了祖国,为了人民,也为了自己人。csdn 真牛X