zoukankan      html  css  js  c++  java
  • c# 打印三角菱形

    //打印三角菱形
     Console.WriteLine("请输入一个数:");
                    int x = Convert.ToInt32(Console.ReadLine());
                    string s = "";
                    string t = "Δ";
                   // string p = "→_→";

                    for (int k = 0; k < x; k++)//左下三角
                    {
                        for (int l = 0; l <= k; l++)
                        {

                            Console.Write(t);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine("--------------------");
                    s = "";
                    for (int m = 0; m < x; m++)//左下三角
                    {
                        for (int n = m; n >= 0; n--)
                        {
                            Console.Write(t);
                        }
                        Console.WriteLine();
                    }

                    Console.WriteLine("--------------------");
                    s = "";
                    for (int mo = 0; mo < x; mo++)//左上三角
                    {
                        for (int no = 0; no < x - mo; no++)
                        {
                            Console.Write(t);
                        }
                        Console.WriteLine();
                    }

                    Console.WriteLine("--------------------");
                    s = "";
                    for (int ml = 0; ml < x; ml++)//左上三角
                    {
                       
                        for (int io = x - ml; io > 0; io--)
                        {

                            Console.Write(t);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine("--------------------");
                    s = "";
                  
                    for (int i = 0; i < x; i++)//尖三角形
                    {
                       
                            for (int k = 0; k<x-i; k++)
                        {
                         
                                 Console.Write(" ");
                         
                        }
                        s = s + t;
                                Console.Write(s);
                      
                        Console.WriteLine();
                     }
                    Console.WriteLine("--------------------");
                    s = "";
                    for (int i = 0; i < x; i++)//右下三角
                    {
                       
                        for (int k = 0; k < x - i; k++)
                        {
                           
                            Console.Write("  ");
                            

                        }
                        s = s + t;
                        Console.Write(s);

                        Console.WriteLine();
                    }
                    Console.WriteLine("--------------------");
                    s = "";
                    for (int i = 0; i < x; i++)//右上三角
                    {
                       
                        for (int k = 0; k <=i; k++)
                        {
                           
                            Console.Write("  ");
                           

                        }
                        for (int k = 0; k <x- i; k++)
                        {
                      
                        Console.Write(t);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine("--------------------");
                    s = "";
                    for (int i = 0; i < x-1; i++)//菱形上部
                    {
                      
                        for (int k = x; k > i+1; k--)
                        {

                            Console.Write("  ");


                        }
                        for (int k = 2*x; k >2 * (x - i)-1; k--)
                        {

                            Console.Write(t);
                        }
                       
                         Console.WriteLine();
                    }
                  
                    for (int i = 0; i < x; i++)//菱形下部
                    {
                        for (int k = 0; k < i; k++)
                        {

                            Console.Write("  ");


                        }
                        for (int k = 0; k <2*( x - i)-1; k++)
                        {
                           
                            Console.Write(t);
                        }
                        Console.WriteLine();
                    }


                    Console.ReadKey();

  • 相关阅读:
    安装armadillo
    windows sublime 2 破解
    ubuntu10.04安装有线网卡驱动
    x250装无线网卡驱动ubuntu
    main restricted universe muitiverse
    apt-get error
    新系統必須安裝的軟件列表
    更新ubuntu軟件源爲阿里雲腳本
    轉載:让重定向>,>>具有root权限
    margin的相关属性:
  • 原文地址:https://www.cnblogs.com/lovesy2413/p/4310478.html
Copyright © 2011-2022 走看看