各位 好友,帮我编一下这个程序嘛!很简单的。

来源:百度知道 编辑:UC知道 时间:2024/06/15 10:10:54
用100元钱买100只鸡,公鸡3元一只,母鸡2元一只,小鸡1元3只。一共有多少种买法。

#include <stdio.h>
void main()
{
int g,m,x;
int count=0;
for(g=0;g<=25;g++)
{

for(m=0;m<=40;m++)
{
x=100-g-m;
if(x%3==0)
{
if(x/3+2*m+3*g==100)
{
count++;
printf("%5d. %5d,%5d,%5d\n",count,g,m,x);
}
}
}
}
printf("count=%d\n",count);
}

结果:
1. 0, 40, 60
2. 5, 32, 63
3. 10, 24, 66
4. 15, 16, 69
5. 20, 8, 72
6. 25, 0, 75
count=6

#include <stdio.h>
void main()
{
int gj, mj, xj, t1, t2;
for (gj=1; gj<=20; gj++)
{
for (mj=1; mj<34; mj++)
{
xj=100-gj-mj;
t1=xj%3;
t2=5*gj+3*mj+xj/3;
if (t1==0&&t2==100)
printf(\"gj=%d,mj=%d,xj=%d\\n\",gj,mj,xj);
}
}

}