使用C#制作金字塔 [英] Making pyramid using c#

查看:391
本文介绍了使用C#制作金字塔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何使用* C#中的金字塔空间?输出将是这样。

My question is how to make a pyramid using * and 'space' in C#? The output will be like this.

     *
    * *
   * * *
  * * * *
 * * * * *

我们只需要使用循环对这一计划。我只知道如何使这一个。

We only need to use "for loop" for this program. I only know how to make this one.

*
**
***
****
*****

我做了一个这样的程序:

I made a program like this:

static void Main(string[]args)
{
int i=o;
int j=o;

for(i=5;1>=1;i--)
  for(j=1;j<=5;j++)
   {
    Console.Write("*");
   }
  Console.WriteLine(" ");
}



我很困惑,当涉及到金字塔,因为它包含空格。感谢您的帮助!

I'm confused when it comes to pyramid because it includes spaces. Thanks for your help!

推荐答案

想想如何你手动打印金字塔。

think about how you'd print the pyramid manually.

假设5级深

1st line: 4 spaces, 1 star,
2nd line: 3 spaces, star, space, star
3rd line: 2 spaces, star space star space star

不要紧,你是否打印空间的最后一个星后或不 - 不会对它的外观

doesn't matter whether you print spaces after the last star or not - won't make a difference to how it looks.

我们看到了什么?

如果我们有一个总的NOx水平的

if we have a total of X levels

line 1: (x-1) spaces, (star space)
line 2: (x-2) spaces, (star space) twice
line 3: (x-3) spaces, (star space) three times
line 4: (x-4) spaces, (star space) four times

这就是模式。当我离开的编码给你。

that's the pattern. I'll leave the coding to you.

这篇关于使用C#制作金字塔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆