• 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();

  • 相关阅读:
    AcWing 1059. 股票买卖 VI Leetcode714. 买卖股票的最佳时机含手续费 dp
    AcWing 1058. 股票买卖 V Leetcode309. 最佳买卖股票时机含冷冻期
    Js取float型小数点后两位数的方法
    浏览器退 事件
    微信中得到的GPS经纬度放在百度,腾迅地图中不准的原因及处理
    dropdownlist 控件的判断
    有一个无效 SelectedValue,因为它不在项目列表中。
    CSS从大图中抠取小图完整教程(background-position应用)
    去掉 input type="number" 右边图标
    页面中星号与字体对齐
  • 原文地址:https://www.cnblogs.com/lovesy2413/p/4310478.html
Copyright © 2020-2023  润新知