不是每种鸡都得有嘛...
#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);
}
}
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编译通过
我这个好象有点绕......