您的位置:首页 > 编程语言 > C#

c#,关于for穷举例题

2016-01-26 15:25 246 查看
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+"买法");

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: