我是靠谱客的博主 整齐故事,这篇文章主要介绍C# 打印三角形,现在分享给大家,希望可以做个参考。

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

namespace demo1
{
    class Program
    {
        static void Main(string[] args)
        {
            string m = Console.ReadLine();
            int n = Convert.ToInt32(m);
            for (int i = 1; i <= n; i++) //打印行数
            {
                for (int j = 1; j <= n - i; j++) //每行打印的空白个数
                {
                    Console.Write(" ");
                }

                for (int j = 1; j <= 2 * i - 1; j++) //每行打印*的个数
                {
                    Console.Write("*");
                }
                Console.WriteLine(); //换行
            }
            Console.ReadLine();
        }
    }
}
 

最后

以上就是整齐故事最近收集整理的关于C# 打印三角形的全部内容,更多相关C#内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部