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

c# while穷举(凑钱)

时间:2015-03-03 16:34:06      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

//1元,2元,5元;凑够20元有多少种可能

int x = 0, y = 0, z = 0, m = 0;

               while (x <= 20)
               {

                   while (y <= 10)
                   {

                       while (z <= 4)
                       {

                           if (x + 2 * y + 5 * z == 20)
                           {
                               Console.WriteLine(x + "," + y + "," + z);
                               m++;
                           }
                           z++;
                       }
                       y++;
                       z = 0;
                   }
                   y = 0;
                   x++;

               }
               Console.WriteLine("总共有" + m + "种可能");

c# while穷举(凑钱)

标签:

原文地址:http://www.cnblogs.com/lovesy2413/p/4311168.html

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