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> ...
随机推荐
- 快速搭建LNMP
[centos 6.4 server]系统安装请参考:http://blog.zhuyin.org/748.html1.防火墙设置: iptables -F service iptables save ...
- Markdown及MarkdownPad使用规则
Markdown Markdown 是一种轻量级标记语言.它允许人们"使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档". Markdown语法简要 ...
- 【转】mysql-5..6.23-win64.zip安装及配置
[强烈建议!!!!]把文件夹的名字也改成如下所说的,不然即使你什么环境配置都对,启动服务的时候依然会出现‘net’不是计算机内部或外部的命令这种令人很郁闷的问题了! 原文链接:http://jingy ...
- .NET防止重复提交数据
最近在做一个销售系统的时候,操作人员提交数据的时候数据库竟然会出现多条数据相同的记录,并且是在1秒之内,客户反馈给我们,第一反应是重复提交的问题,检查了下代码,程序执行完成后应该是跳转到别的页面的,可 ...
- ExportExcel
package cn.com.jansh.core.util; import java.awt.print.Book; import java.io.BufferedInputStream; impo ...
- BZOJ 2038: [2009国家集训队]小Z的袜子(hose)&&莫对算法
这里跟曼哈顿最小生成树没有太大的关系. 时间复杂度证明: [BZOJ2038 小Z的袜子 AC代码] 排序方式: 第一关键字:l所在的块: 第二关键字:r从小到大. #include<cstdi ...
- windows svn利用钩子实现代码同步到web目录
思路: 找 到SVN Server中的仓库(Repositories)文件夹的位置,在相应的项目文件夹中找到hooks文件夹.在该文件夹中添加一个post- commit文件:当有commit动作发 ...
- javaweb入门实例---servlet例子
1.编写servlet: TreeDataServlet.java package com.maggie.tree; import java.io.IOException; import javax. ...
- JDK中的插入排序
算法 有一个已经有序的数据序列,要求在这个已经排好的数据序列中插入一个数,但要求插入后此数据序列仍然有序,这个时候就要用到一种新的排序方法--插入排序法,插入排序的基本操作就是将一个数据插入到已经排好 ...
- spring mvc在Controller中获取ApplicationContext
spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...