1、100块钱买100只鸡,公鸡5元一只,母鸡3元一只,小鸡1元三只,各买多少只鸡?
#region 买鸡编程(不能解方程)
/// <summary>
/// 买鸡编程(不能解方程)
/// </summary>
public void buyChook()
{
//公鸡数量
for (int a = 0, aLen = 100 / 5; a <= aLen; a++)
{
//母鸡数量
for (int b = 0, bLen = (100 - (5 * a)) / 3; b <= bLen; b++)
{
//小鸡数量
int c = (100 - 5 * a - 3 * b) * 3;
if (a + b + c == 100)
Console.WriteLine("100块钱买100只鸡,公鸡5元一只,母鸡3元一只,小鸡1元三只。总共可以购买:\n公鸡:{0}只 \n母鸡:{1}只 \n小鸡:{2}只", a, b, c);
}
}
}
#endregion