c# 穷举法 百鸡

    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
               
                int n = 0;
                for (int g = 1; g*2 <=100; g++)
                {
                    for (int m = 1; m*1 <=100; m++)
                    {
                        for (int x = 1; x*0.5 <=100; x++)
                        {
                            if(g*2+m*1+x*0.5==100&&g+m+x==100)
                            {
                                Console.WriteLine(g+"只公鸡"+m+"只母鸡"+x+"只小鸡");
                               n++;
                            } 
                        }
                    }
                }
                Console.WriteLine("共有"+n+"种可能性");
                Console.ReadLine();
            }
        }
    }
}

 

posted @ 2015-04-19 19:15  王文姿  阅读(412)  评论(0编辑  收藏  举报