百钱买百鸡:
公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,
用100文钱买一百只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱。
#include<stdio.h>
#include<stdlib.h>
void disc()
{
int x,y,z;
for(x=1;x<=20;x++)
{
for(y=1;y<34;y++)
{
for(z=3;z<100;z++)
{
if(5*x+3*y+z/3.0==100&&x+y+z==100)
printf("%d %d%d\n",x,y,z);
}
}
}
}
int main()
{
disc();
}
鸡兔同笼:
公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,
用100文钱买一百只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱。
#include<stdio.h>
#include<stdlib.h>
void disc()
{
int x,y;
int S,N;
printf("InputS,N:");
scanf("%d %d",&S,&N);
for(x=1;x<S;x++)
{
for(y=1;y<S;y++)
{
if(x+y==S&&2*x+4*y==N)
printf("%d %d\n",x,y);
}
}
}
int main()
{
disc();
}