using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
////单位给发了一张150远的购物卡,去买三中东西,洗发水15元,香皂2元,牙刷5元,求刚好花完150元,有多少种卖法,
////每种各买多少?
////设洗发水x 香皂z 牙刷y
//for循环
int a = 0;
for (int x = 0; x <= 10; x++)//假设洗发水为x
{
for (int y = 0; y <= 30; y++)//假设牙刷为y
{
for (int z = 0; z <= 75; z++)//假设香皂为z
{
if (15 * x + 2 * z + 5 * y == 150)//判断计算
{
a++;
Console.WriteLine("够买洗发水" + x + "瓶,香皂" + z + "块,牙刷" + y + "个");
}
}
}
}
Console.WriteLine("共有" + a + "中");
Console.ReadLine();
//百鸡百钱,公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一直。
//共有100问钱,如何凑够100只鸡的情况下,刚好花完100文钱。
int count = 0;
for (int gong = 0; gong <= 50; gong++)
{
for (int mu = 0; mu <= 100; mu++)
{
for (int xiao = 0; xiao <= 200; xiao++)
{
if (gong + mu + xiao == 100 && 2 * gong + 1 * mu + 0.5 * xiao == 100)
{
count++;
Console.WriteLine("够买公鸡" + gong + "只,母鸡" + mu + "只,小鸡" + xiao + "只");
}
}
}
}
Console.WriteLine("共有" + count + "种");
Console.ReadLine();
//for循环的变形得到while循环
//初始条件拿到前面
//循环的状态改变放在魂环体的最后一句
//for变成while,渐远的的分号去掉,只留下循环体。
////纸张厚度0.07毫米
////折叠多少次能够到8848米
int i = 7;
int a = 0;
while (i <= 884800000)
{
i *= 2;
a++;
}
Console.WriteLine(a);
Console.ReadLine();
}
}
}