for循环的嵌套——7月24日
练习一:输入一个正整数,用for循环嵌套求阶乘的和
- //输入一个正整数,求1!+2!+....+n! 用for循环嵌套
- Console.Write("请输入一个正整数:");
- int a = int.Parse(Console.ReadLine());
- int sum = ;
- for (int i = ; i <= a; i++)
- {
- int j = ;
- for (int k = ; k <= i; k++)
- {
- j *= k;
- }
- sum += j;
- }
- Console.WriteLine(sum);
- Console.ReadLine();
练习二:打印九九口诀表
- //打印99口诀表
- //口诀表的规律:相乘的第一个数都是都是列数;相乘的第二个数都是相应行的行数
- for (int i = ; i <= ; i++)//打印行数
- {
- for (int k = ; k <= i; k++)//打印列数
- {
- Console.Write(k + "*" + i + "=" + k * i + "\t");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
练习三:打印矩阵
- //打印矩阵
- for (int k = ; k <= ; k++)
- {
- for (int i = ; i <= ; i++)
- {
- Console.Write("■");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
练习四:左下角为直角的三角形
- //打印左下角为直角的三角形
- for (int k = ; k <= ; k++)
- {
- for (int i = ; i <= k; i++)
- {
- Console.Write("■");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
练习五:左上角为直角的三角形
- //打印左上角为直角
- for (int k = ; k <= ; k++)
- {
- for (int i = ; i >= k; i--)
- {
- Console.Write("■");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
练习六:右上角为直角的三角形
- //打印右上角为直角
- for (int i = ; i <= ; i++)//打印列
- {
- for (int j = ; j <= i - ; j++)
- {
- Console.Write(" ");
- }
- for (int k = ; k >= i; k--)
- {
- Console.Write("■");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
练习七:输入一个数,打印右下角为直角的三角形
- //请输入一个正整数,根据这个数打印一个直角在右下角的等腰直角三角形
- Console.Write("请输入一个正整数:");
- int a = int.Parse(Console.ReadLine());
- for (int i = ; i <= a; i++)//打印列
- {
- for (int k = a - ; k >= i; k--)//打印行的空白处,也可以写成for (int k = 1; k <= a - i ; k++)
- {
- Console.Write(" ");
- }
- for (int j = ; j <= i; j++)//打印图形
- {
- Console.Write("■");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
for循环的嵌套——7月24日的更多相关文章
- 36.React基础介绍——2019年12月24日
2019年12月24日16:47:12 2019年10月25日11:24:29 主要介绍react入门知识. 1.jsx语法介绍 1.1 介绍 jsx语法是一种类似于html标签的语法,它的作用相当于 ...
- SQL PASS将于8月24日在北京中医药大学举办线下活动
活动主题:复制架构的实现和调优以及SQL Server BI在传统行业的应用 地点:北三环东路11号 北京中医药大学 白色的1号楼教学楼后楼5层511房间 时间:2013年8月24日 9:00-12: ...
- 2016年12月24日 星期六 --出埃及记 Exodus 21:19
2016年12月24日 星期六 --出埃及记 Exodus 21:19 the one who struck the blow will not be held responsible if the ...
- 2016年11月24日 星期四 --出埃及记 Exodus 20:15
2016年11月24日 星期四 --出埃及记 Exodus 20:15 "You shall not steal.不可偷盗.
- 2016年10月24日 星期一 --出埃及记 Exodus 19:8
2016年10月24日 星期一 --出埃及记 Exodus 19:8 The people all responded together, "We will do everything th ...
- 2016年6月24日 星期五 --出埃及记 Exodus 14:21
2016年6月24日 星期五 --出埃及记 Exodus 14:21 Then Moses stretched out his hand over the sea, and all that nigh ...
- 6月24日AppCan移动开发者大会礼品清单遭泄露
6月24日,第一届AppCan移动开发者大会将在北京国际会议中心举办,大会以”平台之上,应用无限”为主题,全景展现移动应用发展趋势.AppCan 移动技术蓝图及80万开发者的技术实践成果. 大会现场礼 ...
- 2018年3月24日上海MVP线下技术交流活动简报
2018年3月24日下午,几位上海MVP自发组织了一次线下的技术交流会,主要由MVP胡浩牵头,我(陈晴阳).刘鑫.朱兴亮和胡浩各自做了一次主题演讲,具体主题是: 陈晴阳:<这还是我认识的Visu ...
- 北京Uber优步司机奖励政策(4月24日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
随机推荐
- Java开发中经典的小实例-(随机数)
import java.util.Random;//输出小于33的7个不相同的随机数public class probability { static Random random = new R ...
- FZU 2219 StarCraft(星际争霸)
Description 题目描述 ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2 ...
- django(一)搭建开发环境
本学习系列均使用centos7操作系统,基于python3进行操作.centos7下的python3安装配置http://www.cnblogs.com/Guido-admirers/p/625941 ...
- hdu 4223 Dynamic Programming?
Dynamic Programming? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- R 语言的优劣势是什么?
R 语言的优劣势是什么? 2015-05-27 程序员 大数据小分析 R,不仅仅是一种语言 本文原载于<程序员>杂志2010年第8期,因篇幅所限,有所删减,这里刊登的是全文. 工欲善其 ...
- [转载] what's goole mock
原文: https://code.google.com/p/googlemock/wiki/V1_7_ForDummies 地址被墙了, 看起来费劲, 转载一份 Google C++ Mocking ...
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- Javascript模块化编程(一):模块的写法 (转载 学习中。。。。)
转载地址:http://www.ruanyifeng.com/blog/2012/10/javascript_module.html 阮一峰 大神:http://www.ruanyifeng.com/ ...
- el 和 fmt 常用
EL表达式入门 转自 http://blog.chinaunix.net/uid-9789791-id-1997374.html 隐含对象: pageContext: pageContext对象 pa ...
- RemoteWebDriver管理
直接贴代码: @Parameters({"BrowserType","NodeIP","NodePort"}) public void be ...