码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-06-29 14:56:42      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

问题:公鸡一只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();
        }
    }
}


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

标签:

原文地址:http://blog.csdn.net/lucky51222/article/details/46681673

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!