公鸡5钱一只 母鸡3钱一只c语言,C# “百钱百鸡 公鸡5元一只,母鸡3元一只,小鸡一元3只,用100元买100只鸡"一种做法...

#region 百钱百鸡

Console.Write("公鸡5元一只,母鸡3元一只,小鸡一元3只,用100元买100只鸡");

Console.WriteLine("\n");

/*

int gj=0;

int mj=0;

int xj=0;

int p = 0;

for (gj = 1; gj <= 19;gj++ )

{

for (mj = 1; mj <= 33; mj++)

{

xj = 100 - gj - mj;//获取百中除了公鸡和母鸡后,小鸡的总钱数

Math.DivRem(xj, 3, out p);//计算小鸡的个数

if (((5*gj+3*mj+xj/3)==100)&&p==0)//如果公鸡、母鸡和小鸡的总钱数加起来为100

{

Console.WriteLine("公鸡的个数"+gj);

Console.WriteLine("母鸡的个数"+mj);

Console.WriteLine("小鸡的个数"+xj);

Console.WriteLine("\n");

}

}

}

*/

int allMoney = 100;//100元

int allChicken = 100;//100只

int gj = 5;

int mj = 3;

int xj = 1;

int xjnum = 3;

for (int x = 0; x <= allChicken; x++)

{

for (int y = 0; y <=allChicken; y++)

{

int z = allChicken - x - y;

if (z % xjnum != 0) continue;

z = z / xjnum;

int Money = x * gj + y * mj + z * xj;

if (Money==allMoney)

{

Console.WriteLine("公鸡的个数:{0},母鸡:{1},小鸡:{2}",x,y,z*xjnum);

}

}

}             #endregion             Console.ReadKey();         }

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值