自学内容网 自学内容网

用C#打印等腰三角形,打印四个方向的直角三角形

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _7._19day03
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Print(7);
            Console.WriteLine("------------------");
            Print2(7);
            Console.WriteLine("------------------");
            Print5(7);
            Console.WriteLine("------------------");
            Print4(7);
            Console.WriteLine("------------------");
            Print3(7);

            Console.ReadKey();
        }



        public static void Print(int a)
        {
            for (int i = 1; i <= a; i++)
            {
                for (int j = a - i; j > 0; j--)
                {

                    Console.Write(" ");

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

                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
        public static void Print2(int a)
        {
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a - i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }

        public static void Print3(int a)
        {
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < i + 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }

        public static void Print4(int a)
        {
            for (int i = 0; i < a; i++)
            {
                for (int j = a - 1 - i; j > 0; j--)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j <= i + 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
        }
        public static void Print5(int a)
        {
            for (int i = 0; i < a; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(" ");
                }
                for (int j = a - i; j > 0; j--)
                {
                    Console.Write("*");
                }

                Console.WriteLine();

            }
        }




    }
}


原文地址:https://blog.csdn.net/weixin_64532720/article/details/140558101

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!