不是每种鸡都得有嘛...
#include<stdio.h>
main()
{int x,y,z;
for(x=1;x<=20;x++)
for(y=1;y<=100-x;y++)
{z=100-x-y;
if(5*x+3*y+1.0/3*z==100)
printf("x=%d y=%d z=%d\n",x,y,z);
}
}

不是每种鸡都得有嘛...
#include<stdio.h>
main()
{int x,y,z;
for(x=1;x<=20;x++)
for(y=1;y<=100-x;y++)
{z=100-x-y;
if(5*x+3*y+1.0/3*z==100)
printf("x=%d y=%d z=%d\n",x,y,z);
}
}

	    2006-11-05 20:51
  int main (void)
{
    int counter = 0, chicken, hen, cock;
    
    printf ("cock\t hen\t chicken\n");
    for (cock = 1; cock < 20; cock ++)
    {
        for (hen = 1; hen < 33; hen ++)
        {
            chicken = 3 * (100 - 5 * cock - 3 * hen);
            if (cock + hen + chicken == 100)
                printf ("%d\t %d\t %d\n", cock, hen, chicken),
                counter ++;
        }
    }
    printf ("\nThere are total %d allocations.\n", counter);
    system ("pause");
    return 0;
}
在VC6跟TC2编译通过
我这个好象有点绕......
	    2006-11-05 22:04
  
	    2006-11-05 22:15
  
	    2006-11-06 20:23
  z%3==0&&5*x+3*y+100/3
是不是数据类型出错了?
建议把题目转换一下:
有300元,公鸡 15,母鸡 9,小鸡 1
然后再算,也许就行了
	    2006-11-07 12:34
  #include <stdio.h>
#define CK_1 5
#define CK_2 3
#define CK_3 3 /* 1 RMB for three */
#define SUM 100
int main( )
{
        int x,y,z;
        for (x = 1;x <= 20; x++)
                for ( y = 1;y <= 33; y++)
                {
                        z = SUM - x - y;
                        if ( z <= 0 || z%3 != 0 )
                        {
                                continue;
                        }
                        if ( (CK_1*x + CK_2*y + z/CK_3) != 100 )
                        {
                                continue;
                        }
                        printf("CK1=%d,CK2=%d,CK3=%d\n",x,y,z);
                }
        return 0;
}
执行结果如下:
$ buy_checken
x=4,y=18,z=78
x=8,y=11,z=81
x=12,y=4,z=84
[此贴子已经被作者于2006-11-7 12:56:23编辑过]

	    2006-11-07 12:51
  
	    2006-11-07 15:49
  
	    2006-11-09 18:37