C#趣味程序---百鸡百钱

问题:公鸡一仅仅5元,母鸡一仅仅3元,小鸡三仅仅1元。问100元能够买多少仅仅鸡?

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int z, i=0;
            for (int x = 0; x < 20; x++)
                for (int y = 0; y < 33; y++)
                {
                    z = 100 - x - y;
                    if (5 * x + 3 * y + z / 3 == 100 && z % 3 == 0)
                        Console.WriteLine("{0}.公鸡:{1}"+'\t'+"母鸡:{2}"+'\t'+"小鸡:{3}",++i,x,y,z);
                }
            Console.ReadLine();
        }
    }
}


posted @ 2017-05-26 16:28  yxysuanfa  阅读(365)  评论(0编辑  收藏  举报