不是每种鸡都得有嘛...
#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);
}
}
![](/skin/img/sigline.gif)
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编译通过
我这个好象有点绕......
#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编辑过]