zoukankan      html  css  js  c++  java
  • C#在屏幕上输出一个5行5列的菱形

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 打印一个菱形
    {
        class Program
        {
        ///
        /// 在屏幕上输出一个菱形,5行5列
        ///
        ///   *
        ///  ***
        /// *****
        ///  ***
        ///   *
        /// 将菱形分成两部分输出,上半部分3行,下半部分2行
            static void Main(string[] args)
        {
          for (int i = 1; i <= 3; i++) //上半部分菱形的行数
          {
            for (int j = 0; j < 3 - i; j++) //每行打印空格的个数
            {
               Console.Write(" ");
            }
            for (int k = 0; k < 2 * i - 1; k++) //每行打印*的个数
            {
              Console.Write("*");
            }
            Console.WriteLine();
          }
          for (int i = 1; i <= 2; i++) //下半部分菱形的行数
          {
            for (int j = 0; j < i; j++) //每行打印空格的个数
            {
              Console.Write(" ");
            }
            for (int k = 0; k <= 4 - 2 * i; k++) //每行打印*的个数
            {
              Console.Write("*");
            }
            Console.WriteLine();
          }
          Console.ReadKey();
        }
      }
    }
  • 相关阅读:
    BZOJ 2157: 旅游 (2017.7.21 6:30-2017.7.21 15:38 今日第一题。。)
    洛谷 P1021 邮票面值设计
    洛谷 P2912 [USACO08OCT]牧场散步Pasture Walking
    COGS 2111. [NOIP2015普及]扫雷游戏
    洛谷 P3038 [USACO11DEC]牧草种植Grass Planting
    COGS 1439. [NOIP2013]货车运输
    COGS 908. 校园网
    codevs 1422 河城荷取
    codevs 1183 泥泞的道路
    洛谷 P3390 【模板】矩阵快速幂
  • 原文地址:https://www.cnblogs.com/ahhswyf/p/3434004.html
Copyright © 2011-2022 走看看