zoukankan      html  css  js  c++  java
  • 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 = 1; i <= a;i++ )
                {
                    for (int b = 1; b <= i;b++ )
                    {
                        Console.Write("");
                    }
                    Console.Write("
    ");
                }
                
                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 = 1; b <= a;b++ )
                {
                    for (int c =a; c >= b;c-- )
                    {
                        Console.Write("");
                    }
                    Console.Write("
    ");
                } 
                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 = 1; d <= count; d++)
                    {
    
                        for (int e = count - 1; e >= d; e--)
                        {
    
                            Console.Write(b);
                        }
                        
                        Console.Write(c);
                        for (int x = 0; x < d-1; x++)
                        {
                            Console.Write(c);
                        }
    
                            Console.Write("
    ");
                        
                   
                   
                }
                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 = 1; d <= a; d++)
                {
                   
                    for (int e = 1; e < d;e++ )
                    {
                        Console.Write(b);
    
                        
                    }
    
                    for (int f = a-d; f <= a&&f>=0; f--)
                    {
    
    
                        Console.Write(c);
                    }
                    Console.Write("
    ");
                    
                }
                
                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 = 1; d <= a;d++ )
                {
                    for (int e = a - 1; e >= d ;e-- )
                    {
                        Console.Write(b);
                    }
                    for (int f = 1; f <=(d * 2-1);f++ )
                    {
                        Console.Write(c);
                    }
                    Console.Write("
    ");
                }
                for (int g = 1; g < a;g++ )
                {
                    for (int h = 1; h <= g;h++ )
                    {
                        Console.Write(b);
                    }
                    for (int i =1; i <=( (a-g) *2 - 1);i++ )
                    {
                        Console.Write(c);
                    }
                    Console.Write('
    ');
                }
                Console.ReadLine();
            }
        }
    }

     用for循环嵌套编九九乘法表;

    namespace _2017_2_24__for循环___九九乘法表
    {
        class Program
        {
            static void Main(string[] args)
            {
                for (int a = 1; a <= 9;a++ )
                {
                    for (int b = 1; b <= a;b++ )
                    {
                        Console.Write(a+"*"+b+"="+(a*b)+"	");
                    }
                    Console.Write("
    ");
                }
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    【Java多线程 32】
    python中用input输入时可以回车换行(转帖)
    Python中自定义的实例通过网络进行传送
    《Python网络编程基础》第二章 读书笔记。
    redis操作记录!!!
    流畅的python,Fluent Python 第十五章笔记
    Python并行编程 中文版<中文笔记> 电子版[抄书笔记,仅供自己参考]待更新
    C Primer Plu学习笔记【5-6章节】
    curl使用指南(转帖)
    Python asyncio 异步编程参考资料(全部为url地址)
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6445100.html
Copyright © 2011-2022 走看看