zoukankan      html  css  js  c++  java
  • C#利用for循环打印图形练习题

    (1)

    namespace ConsoleApp2
    {
        class Program
        {
            static void Main(string[] args)
            {
                for(int i = 0; i < 5; i++)//外层循环控制的是行数
                {
                    for(int j = 0; j <= i; j++)//内层循环控制的是列数,控制是每行打印的内容及个数
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }

     打印结果如下:

     (2)

    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                for(int i = 0; i < 5; i++)
                {
                    for(int j = 5; j > i; j--)
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }

    打印结果如下:

    (3)

    namespace ConsoleApp4
    {
        class Program
        {
            static void Main(string[] args)
            {            
                for(int i = 0; i < 5; i++)//打印行数
                {
                    for(int j = 5; j >i+1; j--)//打印空格数列数
                    {
                        Console.Write(" ");
                    }
                    for(int t = 0; t <= i; t++)//打印列数
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }

    打印结果如下:

    (4)

    namespace ConsoleApp5
    {
        class Program
        {
            static void Main(string[] args)
            {
                for(int i = 0; i < 5; i++)
                {
                    for(int j = 0; j <=i-1; j++)
                    {
                        Console.Write(" ");
                    }
                    for(int t = 5; t > i; t--)
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }

    打印结果如下:

  • 相关阅读:
    node.js 笔记一
    mysql 错误2203 1061 及安装最后出现2003现象的解决办法
    git shell 命令大全
    Mysql常用命令行大全
    php 魔术方法 说明
    php linux 环境搭建
    Linux下源码编译安装MySQL 5.5.8
    linux 压缩解压缩命令
    ftp 命令全集
    sublime text2
  • 原文地址:https://www.cnblogs.com/programme-maker/p/10780057.html
Copyright © 2011-2022 走看看