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> ...
随机推荐
- git 关联远程库(https协议)
1.在oschina上新建库 2.在本地文件夹右键->"git Bash here" 3.设置全局变量: git config --global user.name &quo ...
- ios数据存储——对象归档
归档:数据从内存与闪存相互转化,类似“序列化”,将数据转换成二进制字节数据 操作:有两种方式,第一种是单个对象作为root进行归档和恢复,一个对象一个文件:第二种,可以同时归档多个对象到一个文件 注意 ...
- 最新的thinkphp 后台入口的问题
新的thinkphp后台入口绑定了单独了文件 admin.php 要注意.
- css强制折行和隐藏超出部分
一.强制换行1 word-break: break-all; 只对英文起作用,以字母作为换行依据. 2 word-wrap: break-word; 只对英文起作用,以单词作为换行依据. 3 whit ...
- 使用 System.Transactions 进行事物管理
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- C#子窗口与父窗口交互(使用委托和事件)
目标:在子窗口Form2上单击按钮时向Form1传递一组自定义参数,并显示在父窗口Form1上. 方法:有很多方法,这里只介绍委托和事件的实现方式. 思路:Form2中定义事件,Form1创建Form ...
- 关于android:id="@+id/xx"的理解
之前学习android的时候,对android:id="@+id/xx"总感觉混淆,不理解,刚看了一篇文章.现在貌似是恍然大悟.故做了一下笔记,希望帮助有共同问题的人... and ...
- 完美解决夏天电脑cpu发烫问题
最近有朋友跟我反馈,说苹果电脑虽然好用,但是一直有一个问题困扰着他,就是电脑散热的问题.每到夏天的时候,电脑运转之后就会发烫,用的特别的不舒服. 相信用电脑的都会有这样的感受吧,更加相信你们都用过以下 ...
- 关于ExtJS必输框,多选项
必填项: //页面内传值用ID,和后台联系用name <div class="col-xs-4"> <div class= ...
- Objective-C 关于静态方法与实例方法的转载
objective-c中非常重要的语法知识,在此归纳总结一下. 类方法,也称静态方法,指的是用static关键字修饰的方法.此方法属类本身的方法,不属于类的某一个实例(对象).类方法中不可直接使用实例 ...