for:
for(初始条件,条件表达式,状态改变)
{
循环体
}
//100块钱,买2元一只的圆珠笔,3块钱一个的尺子,5元一个的铅笔盒,每样至少一个,正好花光,请问有多少中画法。
//一张纸0.00007m,折多少次和珠峰一样高
//100以内质数
//一对幼兔,1个月后长成小兔,再过一个月长成成兔并且生下一对幼兔,问24月后共有多少兔子。
#region==猜拳题目==
/*
//猜拳,剪刀-0 石头-1 布-2
Random r = new Random();//生成随机数
int diannao = r.Next(3);//生成0-3之间,不包括3的数
Console.Write("请出拳:剪刀-0 石头-1 布-2 :");
int ren = int.Parse(Console.ReadLine());//控制台录入字符串,转换为int类型
Console.WriteLine("电脑出拳:{0}",diannao);
if (diannao - ren == -1 || ren - diannao == -2)//所有人赢的情况
{
Console.WriteLine("恭喜你,你赢了");
}
else if (diannao == ren)
{
Console.WriteLine("平局");
}
else
{
Console.WriteLine("输了");
}
*/
#endregion
////循环 for
//for (int i = 1; i <= 10; i++)
//{
// Console.WriteLine("你好"+i);
//}
/*
int renying = 0;
int dnying = 0;
for (int i = 1; i <= 3; i++)
{
Random r = new Random();//生成随机数
int diannao = r.Next(3);//生成0-3之间,不包括3的数
Console.Write("请出拳:剪刀-0 石头-1 布-2 :");
int ren = int.Parse(Console.ReadLine());//控制台录入字符串,转换为int类型
Console.WriteLine("电脑出拳:{0}", diannao);
if (diannao - ren == -1 || ren - diannao == -2)//所有人赢的情况
{
renying++;
Console.WriteLine("恭喜你,你赢了");
}
else if (diannao == ren)
{
Console.WriteLine("平局");
}
else
{
dnying++;
Console.WriteLine("输了");
}
}
if (renying >= 2)
{
Console.WriteLine("三局两胜人赢了");
}
if (dnying >= 2)
{
Console.WriteLine("三局两胜电脑赢了");
}
*/
//累加求和
/*
int sum = 0;
Console.Write("请输入数字:");
int shu = int.Parse(Console.ReadLine());
for (int i = 1; i <= shu; i++)
{
sum = sum + i;
}
Console.WriteLine("结果为:"+sum);
*/
/*
* //输出偶数
Console.Write("请输入数字:");
int shu = int.Parse(Console.ReadLine());
for (int i = 1; i <= shu; i++)
{
if (i % 2 == 0)
{
Console.WriteLine(i);
}
}
*/
/*
//与7相关的数
for (int i = 1; i <= 100; i++)
{
if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
{
Console.WriteLine(i);
}
}
*/
/*
//求阶乘
int sum = 1;
Console.Write("请输入数字:");
int shu = int.Parse(Console.ReadLine());
for (int i = 1; i <= shu; i++)
{
sum = sum * i ;
}
Console.WriteLine("结果为:" + sum);
*/
/*
int sum = 0;
Console.Write("请输入数字:");
int shu = int.Parse(Console.ReadLine());
for (int i = 1; i <= shu; i++)//从1开始遍历
{
int jiecheng = 1;
//求i的阶乘
for (int j = 1; j <= i; j++)
{
jiecheng = jiecheng*j;
}
sum = sum + jiecheng;//累加
}
Console.WriteLine("结果为:" + sum);
*/
/*
//篮球
Console.Write("请输入次数:");
int n = int.Parse(Console.ReadLine());
decimal height = 10M;
for (int i = 1; i <= n; i++)
{
height = height * 3 / 4;
}
Console.WriteLine("高度为:"+height);
*/
//穷举
//100块钱,买2元一只的圆珠笔,3块钱一个的尺子,
//5元一个的铅笔盒,每样至少一个,正好花光,
//有多少种花法。
/*
Console.WriteLine("圆珠笔 尺子 铅笔盒");
int count = 0;
for (int i = 1; i <= 50; i++)
{
for (int j = 1; j <= 33; j++)
{
for (int k = 1; k <= 20; k++)
{
if (i * 2 + j * 3 + k * 5 == 100)
{
Console.WriteLine("圆珠笔:{0},尺子{1},铅笔盒{2}",i,j,k);
count++;
}
}
}
}
Console.WriteLine("总个数为:" + count);
*/
//一张纸0.00007m,折多少次和珠峰一样高
/*
decimal hou = 0.00007M;
for (int i = 1; i > 0; i++)
{
hou = hou * 2;
if (hou > 8848)
{
Console.WriteLine(i);
break;//跳出循环
}
}
*/
//100以内质数
/*
for (int k = 1; k <= 100; k++)
{
int count = 0;
for (int i = 1; i <= k; i++)
{
if (k % i == 0)
{
count++;
}
}
if (count == 2)
{
Console.WriteLine(k);
}
}
*/
//100以内质数和
int sum = 0;
for (int k = 1; k <= 100; k++)
{
int count = 0;
for (int i = 1; i <= k; i++)
{
if (k % i == 0)
{
count++;
}
}
if (count == 2)
{
sum += k;
}
}
Console.WriteLine(sum);
//兔子
Console.Write("请输入一个月数:");
int mon = int.Parse(Console.ReadLine());
int youtu = 1, xiaotu = 0, chengtu = 0;
for (int i = 2; i <= mon; i++)
{
chengtu = xiaotu + chengtu;
xiaotu = youtu;
youtu = chengtu;
}
int sum = chengtu + xiaotu + youtu;
Console.WriteLine(sum);