我是靠谱客的博主 可靠河马,这篇文章主要介绍c#三角形输出,现在分享给大家,希望可以做个参考。

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

namespace sanjiao01
{
    class Program
    {
        static void Main(string[] args)
        {
          
                int n;
                string inStr;
                Console.WriteLine("请输入一个 1-20 之间的整数:");
                inStr = Console.ReadLine();
                if (int.TryParse(inStr, out n) == true)
                {
                    three(n);
                }
                else Console.WriteLine(inStr + "不能转换成整型");
                Console.ReadKey();
            }
            static void three(int n)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= (n - (i + 1)); j++)
                {
                    Console.Write(" ");

                }
                for (int j = 0; j < 2 * i + 1; j++)
                {
                    Console.Write("*");

                }
                Console.WriteLine();
            }
        }
    }
}

 

最后

以上就是可靠河马最近收集整理的关于c#三角形输出的全部内容,更多相关c#三角形输出内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(162)

评论列表共有 0 条评论

立即
投稿
返回
顶部