用几个练习题演示一下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循环的嵌套的更多相关文章

  1. 第五篇:python基础之循环结构以及列表

    python基础之循环结构以及列表   python基础之编译器选择,循环结构,列表 本节内容 python IDE的选择 字符串的格式化输出 数据类型 循环结构 列表 简单购物车的编写 1.pyth ...

  2. iOS静态库.a总结(2017.1.24增加脚本打包方法)

    修改于:2017.1.24 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.根据源代码的公开情况,库可以分为2种类型 a.开源库 公开源代码,能看到具体实现 ,比如SDWebImag ...

  3. 电脑小白学习软件开发-C#语言基础之循环重点讲解,习题

    写代码也要读书,爱全栈,更爱生活.每日更新原创IT编程技术及日常实用视频. 我们的目标是:玩得转服务器Web开发,搞得懂移动端,电脑客户端更是不在话下. 本教程是基础教程,适合任何有志于学习软件开发的 ...

  4. VBS基础篇 - 循环语句(3) - For...Next

    VBS基础篇 - 循环语句(3) - For...Next   指定循环次数,使用计数器重复运行语句,语法结构如下: 1 2 3 4 5 For counter = start To end [Ste ...

  5. VBS基础篇 - 循环语句(4) - For Each...Next

    VBS基础篇 - 循环语句(4) - For Each...Next   For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次 ...

  6. 2017 Android 面试题 [ 基础与细节 ]

    2017 Android 面试题 [ 基础与细节 ] 感谢@chuyao抛出的这些问题,平时业务代码写多了,很多基础的东西变得含糊不清了,这次裸辞出来找工作确实没有之前顺利,顺便求上海Android开 ...

  7. Becoming inspired - ASC - 2017 MARCH 24

    Becoming inspired - The 11 questions to ask yourself when you feel uninspired @ Advanced Studio Clas ...

  8. Python 基础 while 循环

    Python 基础 while 循环 while 循环 在生活中,我们遇到过循环的事情吧?比如循环听歌.在程序中,也是存才的,这就是流程控制语句 while 基本循环 while 条件: # 循环体 ...

  9. 基础语法-for循环的嵌套

    基础语法-for循环的嵌套 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.for循环嵌套概述 说白了就是在for循环中再嵌套一层for循环. 二.for循环嵌套案例 1> ...

随机推荐

  1. C语言-基础

    程序是为了让计算机完成某项任务而编写的逐条执行的指令序列. C语言的特点是:结构化,语言简洁,功能强大,移植性好. 因为移植性好,所以大多数单片机如51.stm32,msp430,等众多嵌入式微处理器 ...

  2. js动画学习笔记

    <html> <head> <meta charest="utf-8"> <title>test</title> < ...

  3. jdk1.8中的for循环

    jdk1.8 从语法角度,感觉发生的变化还是蛮大的.在此记录一下. for 循环 public static void main(String[] args) { List<Animal> ...

  4. UVa 507 - Jill Rides Again

    题目大意:最大和子序列问题.由于具有最大和的子序列具有一下性质:第一项不为负数,并且从第一项开始累加,中间不会有和出现负数,因为一旦有负数我们可以抛弃前边的部分以得到更大的子序列和,这将会产生矛盾. ...

  5. ubuntu下常用的apt-get 命令参数

    apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt-get install package ...

  6. linux 下source、sh、bash、./执行脚本的区别

    原文地址:http://blog.csdn.net/caesarzou/article/details/7310201 source命令用法: source FileName 作用:在当前bash环境 ...

  7. Mysql表锁、行锁、页锁

    参考 http://www.jb51.net/article/50047.htm <MySQL行级锁.表级锁.页级锁详细介绍> 页级:引擎 BDB.表级:引擎 MyISAM , 理解为锁住 ...

  8. Java线程:堵塞队列与堵塞栈

    一.堵塞队列 Java定义了堵塞队列的接口java.util.concurrent.BlockingQueue,堵塞队列是一个指定长度的队列,当试图向队列中添加元素而队列已满,或者是想从队列移出元素而 ...

  9. 介绍一个开源的在线管理SQLServer的小工具--SQLEntMan

    近来有许多人问起SQL在线管理的问题,遂将以前用过的一个开源SQL 在线管理工具修改了一下,并分享. 看下效果图: 原项目的地址:http://sourceforge.net/projects/asp ...

  10. wx小程序初体验

    小程序最近太火,不过相比较刚发布时,已经有点热度散去的感觉,不过这不影响我们对小程序的热情,开发之前建议通读下官网文档,附链接:https://mp.weixin.qq.com/debug/wxado ...