首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >三角形仿射在C#中的应用

问三角形仿射在C#中的应用
EN

Stack Overflow用户
提问于 2016-07-20 05:57:07
回答 1查看 2K关注 0票数 0

我不能在学校里解决我的三角形程序,它是用这个程序用系统打印单面曲线;

代码语言:javascript
复制
namespace starpyramid
{ 
    class program 
    { 
        static void Main() 
        { 
            Console.Write("Height: "); 
            int i = int.Parse(Console.ReadLine());
            if(i>0)
            {
            goto main;
            }
            else
            {
                Main();
            }   

            main:
            Console.Write("\n");
            for (int h = 1; h<= i;h++) // main loop for the lines
            {
                for (int s = h; s <= i; s++) //for spaces before the stars
                {
                    Console.Write(" ");
                }
                for(int j=1; j<(h*2); j=j+2)
                {
                    Console.Write("*");
                }
            Console.Write("\n");
            }
    }   
    } 
}

但我需要修改它,使它成为一个适当的三角形!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-20 06:01:18

这里有一个解决方案:

代码语言:javascript
复制
public static void DrawPyramid(int Rows)
{
    string Pyramid = string.Empty;
    int n = Rows;
    for (int i = 0; i <= n; i++)
    {
        for (int j = i; j < n; j++)
        {
            Pyramid += " ";
        }
        for (int k = 0; k < 2 * i - 1; k++)
        {
            Pyramid += "*";
        }
        Pyramid += Environment.NewLine;
    }
    Pyramid.ConsoleWrite();
}

示例:

代码语言:javascript
复制
DrawPyramid(5);

//     *  
//    ***   
//   ***** 
//  *******
// *********
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38473332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档