练习一:输入一个整数,求从1到这个数的累加和

//练习1:输入一个整数,计算从1加到这个数的结果
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
for (int i = ; i <= a; i++)
{
sum += i;//sum=sum+i
}
Console.WriteLine(sum);
Console.ReadLine();

练习二:输入一个正整数,求1到这个数的阶乘

//练习2:输入一个正整数,求阶乘
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int j = ;
for (int i = ; i <= a; i++)
{
j *= i;//j=j*i
}
Console.WriteLine(j);
Console.ReadLine();

练习三:输入一个正整数,求它的阶乘和

//练习3:输入一个正整数,求阶乘的和:1!(1阶乘)+2!+....+a!
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int j = ;
int sum = ;
for (int i = ; i <= a; i++)
{
j *= i;
//if (i == 4)//如果不想要4!的累加
//{
// continue;//终止本次循环,继续下次循环。braek是终止整个循环,跳出循环
//}
sum += j;
}
Console.WriteLine(sum);
Console.ReadLine();

练习四:输入游戏关卡数,求当前分数

//练习4:一个游戏,前20关的分数是每一关自身,
//21~30关,每一关是10分
//31~40关,每一关是20分
//41~49关,每一关是30分
//50关,是100分
//输入你现在闯到的关卡数,求你现在拥有的分数
//两种做法:if嵌套for for嵌套if Console.Write("请输入您现在的关卡数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
//for嵌套if
if (a >= && a <= )
{
for (int i = ; i <= a; i++)
{
if (i >= && i <= )
{
sum += i;
}
else if (i >= && i <= )
{
sum += ;
}
else if (i >= && i <= )
{
sum += ;
}
else if (i >= && i <= )
{
sum += ;
}
else//i=50
{
sum += ;
}
}
Console.WriteLine("您现在的分数是:" + sum);
}
else
{
Console.WriteLine("您输入的关卡数有误!");
}
Console.ReadLine(); //if嵌套for
if(a >= && a <= )
{
if (a >= && a <= )
{
for (int i = ; i <= a; i++)
{
sum += i;
}
}
else if (a >= && a <= )
{
for (int i = ; i <= ; i++)
{
sum += i;
}
for (int i = ; i <= a; i++)
{
sum += ;
}
}
else if (a >= && a <= )
{
for (int i = ; i <= ; i++)
{
sum += i;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
for (int i = ; i <= a; i++)
{
sum += ;
}
}
else if (a >= && a <= )
{
for (int i = ; i <= ; i++)
{
sum += i;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
for (int i = ; i <= a; i++)
{
sum += ;
}
}
else//a==50
{
for (int i = ; i <= ; i++)
{
sum += i;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
for (int i = ; i <= ; i++)
{
sum += ;
}
sum += ;
}
Console.WriteLine("您现在的分数是:" + sum);
}
else
{
Console.WriteLine ("您的输入有误!");
}
Console.ReadLine();

练习五:找出100以内与7有关的数

//练习5:找出100以内与7有关的数
//分析:i % 10 == 7 || i % 7 == 0 || i / 10 == 7
for (int i = ; i <= ; i++)
{
if (i % == || i % == || i / == )
{
Console.Write(i + "\t");
}
}
Console.ReadLine();

练习六:100节楼梯,输入楼梯数,计算本节楼梯的分数

//练习6:100节楼梯,0-49节的每一节是本身的分数,
//从50开始是每一关10分。
//输入现在所到的节数,求现在的分数 Console.Write("请输入您现在的节数:");
int a=int.Parse (Console.ReadLine());
int sum = ;
//if嵌套for
if (a >= && a <= )
{
for (int i = ; i <= a; i++)
{
sum += i;
}
Console.WriteLine("您现在的分数是:" + sum);
}
else if (a >= && a <= )
{
for (int i = ; i <= ; i++)
{
sum += i;
}
for (int i = ; i <= a; i++)
{
sum += ;
}
Console.WriteLine("您现在的分数是:" + sum);
}
else
{
Console.WriteLine("您的输入有误!");
}
Console.ReadLine(); //for嵌套if
if (a >= && a <= )
{
for (int i = ; i <= a; i++)
{
if (i >= && i <= )
{
sum += i;
}
else//i>=50&&i<=100
{
sum += ;
}
}
Console.WriteLine("您现在的分数是:" + sum);
}
else
{
Console.WriteLine("您的输入有误!");
}
Console.ReadLine();

for循环练习——7月23日的更多相关文章

  1. 2016年12月23日 星期五 --出埃及记 Exodus 21:18

    2016年12月23日 星期五 --出埃及记 Exodus 21:18 "If men quarrel and one hits the other with a stone or with ...

  2. [分享] 从定制Win7母盘到封装详细教程 By BILL ( 10月23日补充说明 )

    [分享] 从定制Win7母盘到封装详细教程 By BILL ( 10月23日补充说明 ) billcheung 发表于 2011-10-23 00:07:49 https://www.itsk.com ...

  3. 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦

    听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何?        上周奥威公开 ...

  4. 2016年11月23日 星期三 --出埃及记 Exodus 20:14

    2016年11月23日 星期三 --出埃及记 Exodus 20:14 "You shall not commit adultery.不可奸淫.

  5. 2016年10月23日 星期日 --出埃及记 Exodus 19:7

    2016年10月23日 星期日 --出埃及记 Exodus 19:7 So Moses went back and summoned the elders of the people and set ...

  6. 2016年6月23日 星期四 --出埃及记 Exodus 14:20

    2016年6月23日 星期四 --出埃及记 Exodus 14:20 coming between the armies of Egypt and Israel. Throughout the nig ...

  7. Week16(12月23日):复习

    Part I:提问 =========================== 1.声明强类型视图时,使用关键字(    ) A.ViewBag    B.model    C.Type    D.Tit ...

  8. 2017年3月23日 坚果性能测试Loadrunner 免费公开课

    2017-03-23  坚果性能测试1群 607937164  我昨天看了一下飞扬老师的讲义PPT,真的很棒,BAT的专业性能老师果然是有好几把刷子,十分受教,相信周四的公开课一定会让大家收益颇丰的. ...

  9. 成都Uber优步司机奖励政策(4月23日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

随机推荐

  1. JAVAWEB安全开发

    晚上在看司马的博客,看到一篇关于JAVA安全的,基础的,蛮不错的,给大家分享下 文章来源是司马的博客:http://www.nxadmin.com/web/1332.html ============ ...

  2. plot bar chart using python

    Example import matplotlib.pyplot as plt import plotly.plotly as py # Learn about API authentication ...

  3. Python基础学习笔记(三)运算符

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-chinese-encoding.html 3. http://w ...

  4. ruby的正则表达式-scan方法

    irb(main):001:0> str_vps=%Q{viewpoint_ids: [{"id":"260e053b-d728-4785-888d-eb4f1ca ...

  5. redis数据库选择-select

    1.关于redis的select命令用法: SELECT index 切换到指定的数据库,数据库索引号 index 用数字值指定,以 0 作为起始索引值. 默认使用 0 号数据库. 可用版本: > ...

  6. ORACLE 查询日志

    SQL>select * from v$sql (#查看最近所作的操作) SQL>select * fromv $sqlarea(#查看最近所作的操作)

  7. 如何读懂 STATSPACK 报告 (转) & Toad 结合

    可与 toad 相结合的内容, 用 这种颜色可以利用 toad(database->monitor->server statistics)查看到下边的很多信息, 比如 wait event ...

  8. hdu 4521 小明系列问题——小明序列(线段树 or DP)

    题目链接:hdu 4521 本是 dp 的变形,却能用线段树,感觉好强大. 由于 n 有 10^5,用普通的 dp,算法时间复杂度为 O(n2),肯定会超时.所以用线段树进行优化.线段树维护的是区间内 ...

  9. Android LayoutInflater 动态地添加删除View

    我想实现点击一个按钮(或其他的事件)添加或删除View,网上找到了LayoutInflater这个类. 下面是我自己一些经验: android官网上LayoutInflater的API:http:// ...

  10. Statspack安装配置及使用

    1.1 概念 statspack,用于收集系统信息,诊断数据库故障,也方便第三方技术支持进行远程阅读和建议.它连续收集数据信息,能够提供趋势分析,同时也需要单独分配一个表空间来存储这些统计数据.即在安 ...