2017-2-24 C#基础 for循环的嵌套
用几个练习题演示一下for循环的嵌套
1、打印以下图形
★
★★
★★★
★★★★
★★★★★
namespace _2017_2_24_for循环的嵌套
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个数字:");
int a=Convert.ToInt32(Console.ReadLine());
for (int i = ; i <= a;i++ )
{
for (int b = ; b <= i;b++ )
{
Console.Write("★");
}
Console.Write("\n");
} Console.ReadLine();
}
}
}
★★★★★
★★★★
★★★
★★
★
namespace _2017_2_24_for循环的嵌套_画星星2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入数字"); int a = Convert.ToInt32(Console.ReadLine());
for (int b = ; b <= a;b++ )
{
for (int c =a; c >= b;c-- )
{
Console.Write("★");
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
○○○○★
○○○★★
○○★★★
○★★★★
★★★★★
namespace _2017_2_24_for循环的嵌套__画星星3
{
class Program
{
static void Main(string[] args)
{ Console.WriteLine("请输入一个数字");
int count = Convert.ToInt32(Console.ReadLine());
String b = " "; String c = "※"; for (int d = ; d <= count; d++)
{ for (int e = count - ; e >= d; e--)
{ Console.Write(b);
} Console.Write(c);
for (int x = ; x < d-; x++)
{
Console.Write(c);
} Console.Write("\n"); }
Console.ReadLine();
}
}
}
★★★★★
★★★★
★★★
★★
★
namespace _2017_2_24_for_循环_的嵌套__画星星4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个数字:");
int a=Convert.ToInt32( Console.ReadLine());
String b=" ";String c="☆";
for (int d = ; d <= a; d++)
{ for (int e = ; e < d;e++ )
{
Console.Write(b); } for (int f = a-d; f <= a&&f>=; f--)
{ Console.Write(c);
}
Console.Write("\n"); } Console.ReadLine();
}
}
}
★
★★★
★★★★★
★★★★★★★
★★★★★★★★★
★★★★★★★
★★★★★
★★★
★
namespace _2017_2_24__for循环的嵌套___打印菱形
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入一个数字:");
int a = Convert.ToInt32(Console.ReadLine());
String b="○";String c="★";
for (int d = ; d <= a;d++ )
{
for (int e = a - ; e >= d ;e-- )
{
Console.Write(b);
}
for (int f = ; f <=(d * -);f++ )
{
Console.Write(c);
}
Console.Write("\n");
}
for (int g = ; g < a;g++ )
{
for (int h = ; h <= g;h++ )
{
Console.Write(b);
}
for (int i =; i <=( (a-g) * - );i++ )
{
Console.Write(c);
}
Console.Write('\n');
}
Console.ReadLine();
}
}
}
用for循环嵌套编九九乘法表;
namespace _2017_2_24__for循环___九九乘法表
{
class Program
{
static void Main(string[] args)
{
for (int a = ; a <= ;a++ )
{
for (int b = ; b <= a;b++ )
{
Console.Write(a+"*"+b+"="+(a*b)+"\t");
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
2017-2-24 C#基础 for循环的嵌套的更多相关文章
- 第五篇:python基础之循环结构以及列表
python基础之循环结构以及列表 python基础之编译器选择,循环结构,列表 本节内容 python IDE的选择 字符串的格式化输出 数据类型 循环结构 列表 简单购物车的编写 1.pyth ...
- iOS静态库.a总结(2017.1.24增加脚本打包方法)
修改于:2017.1.24 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.根据源代码的公开情况,库可以分为2种类型 a.开源库 公开源代码,能看到具体实现 ,比如SDWebImag ...
- 电脑小白学习软件开发-C#语言基础之循环重点讲解,习题
写代码也要读书,爱全栈,更爱生活.每日更新原创IT编程技术及日常实用视频. 我们的目标是:玩得转服务器Web开发,搞得懂移动端,电脑客户端更是不在话下. 本教程是基础教程,适合任何有志于学习软件开发的 ...
- VBS基础篇 - 循环语句(3) - For...Next
VBS基础篇 - 循环语句(3) - For...Next 指定循环次数,使用计数器重复运行语句,语法结构如下: 1 2 3 4 5 For counter = start To end [Ste ...
- VBS基础篇 - 循环语句(4) - For Each...Next
VBS基础篇 - 循环语句(4) - For Each...Next For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次 ...
- 2017 Android 面试题 [ 基础与细节 ]
2017 Android 面试题 [ 基础与细节 ] 感谢@chuyao抛出的这些问题,平时业务代码写多了,很多基础的东西变得含糊不清了,这次裸辞出来找工作确实没有之前顺利,顺便求上海Android开 ...
- Becoming inspired - ASC - 2017 MARCH 24
Becoming inspired - The 11 questions to ask yourself when you feel uninspired @ Advanced Studio Clas ...
- Python 基础 while 循环
Python 基础 while 循环 while 循环 在生活中,我们遇到过循环的事情吧?比如循环听歌.在程序中,也是存才的,这就是流程控制语句 while 基本循环 while 条件: # 循环体 ...
- 基础语法-for循环的嵌套
基础语法-for循环的嵌套 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.for循环嵌套概述 说白了就是在for循环中再嵌套一层for循环. 二.for循环嵌套案例 1> ...
随机推荐
- PreparedStatement接口
从实际来讲,Statement现在已经不使用了,他已经称为了历史. Statement执行关键性问题在于他需要一个完整 的字符串定义要使用的SQL语句,而PreparedStatement可以动态的设 ...
- c#第5章 变量的更多内容 隐式和显式转换、枚举、结构、数组、
1.目标数据 destination 英[ˌdestɪˈneɪʃn] 美[ˌdɛstəˈneʃən] n. 目的,目标; 目的地,终点; [罕用语] 预定,指定; 2.源数据 source 英[sɔ: ...
- Hibernate的一些事儿
一.Hibernate的工作原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6.提 ...
- 汇编语言实现led灯的跑马灯
led实验1.看原理图 看设备工作的原理(可能需要阅读芯片手册),看设备与cpu的连接关系 GPIO具有输入输出功能.输入:cpu想知道io引脚是高电平还是低电平那么就是输入方式输出:cpu想控制io ...
- mysql 用户管理 权限控制
添加用户 insert into mysql.user(Host,User,Password) values("%","shenen",password(&qu ...
- JavaScript中typeof和instanceof深入详解
这次主要说说javascript的类型判断函数typeof和判断构造函数原型instanceof的用法和注意的地方. typeof 先来说说typeof吧.首先需要注意的是,typeof方法返回一个字 ...
- thinkphp 配置项总结
'URL_PATHINFO_DEPR'=>'-',//修改URL的分隔符 'TMPL_L_DELIM'=>'<{', //修改左定界符 'TMPL_R_DELIM'=>'}&g ...
- python如何安装模块
1.从 https://pypi.python.org/pypi/XXXX 下载压缩包 2.解压所下载的压缩包 3.CD到解压目录,执行 sudo python setup.py install
- 使用AngularJS的三个重要原因
入门教程:http://www.ituring.com.cn/minibook/303 : http://angularjs.cn/tag/AngularJS 原因一:Google开发的框架 要知道开 ...
- 《微信小程序七日谈》- 第六天:小程序devtool隐藏的秘密
<微信小程序七日谈>系列文章: 第一天:人生若只如初见: 第二天:你可能要抛弃原来的响应式开发思维: 第三天:玩转Page组件的生命周期: 第四天:页面路径最多五层?导航可以这么玩: 第五 ...