标签:
迭代法:
#region ======猴子吃桃,每天吃一半扔一个、吃七天第七天剩一个======
int he = 1;
for (int i = 6; i >= 1; i--)
{
he = (he + 1) * 2;
Console.WriteLine("第" + i + "天桃子有" + he + "个");
}
Console.WriteLine("第一天有桃子" + he + "个");
#endregion
穷举法:
int a = 0;//牙刷
int b = 0;//香皂
int c = 0;//洗发水
int su = 0;//记数
for (a = 0; a <= 20; a++)
{
for (b = 0; b <= 50; b++)
{
for (c = 0; c <= 6; c++)
{
if (a * 5 + b * 2 + c * 15 == 100)
{
Console.WriteLine("牙刷{0},香皂{1},洗发水{2}:", a, b, c);
su++;
}
}
}
}
Console.WriteLine("共有{0}种组合", su);
break 终止循环
contiune 中断循环,进入下一次循环
标签:
原文地址:http://www.cnblogs.com/yongjiapei/p/5401208.html