c#,关于for穷举例题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace for穷举
{
    class Program
    {
        static void Main(string[] args)
        {
            int cishu = 0;
            for (int x = 0; x <= 150;x++ )
            {
                for (int y = 0; y <= 75;y++ )
                {
                    for (int z = 0; z <= 30;z++ )
                    {
                        if (x * 1 + y * 2 + z * 5 == 150)
                        {
                            cishu++;
                            Console.WriteLine("第"+cishu+"种买法,"+x+"个一分,"+y+"个两分,"+z+"个五分");
                        }
                    }
                }
            }
            Console.WriteLine("一共有"+cishu+"买法");

        }
    }
}

posted @ 2016-01-26 15:25  什么玩楞啊,我叫旺仔  阅读(142)  评论(0编辑  收藏  举报