金字塔形状中的数字 [英] Numbers in a pyramid shape

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

问题描述

早上好,



我有文本框和按钮。如果我在文本框中输入一个数字然后按一个按钮,就会出现很多行数。



例如,



如果我给2,

1

2 3



我的代码是


good morning,

i have textbox and a button. if i give a number in text box and press a button, that many no of rows of numbers should come.

for example,

if i give 2,
1
2 3

my code is

int n = int.Parse(txtenternoofrows.Text);

       int i, j, k = 1;

       for (i = 1; i < n; i--)
       {
           for (j = 1; j < i - 1; j--)
           {
               Response.Write(k--);
           }
           Response.Write("<br/>");
       }







谢谢




thank you

推荐答案

这是非常基本的逻辑。在我的代码中,我假设使用输入5并设置n = 5.



This is very basic logic. In my code I assume that the use entered 5 and set the n= 5.

private void display()
       {
           int n = 5;
           int count = 0;

           for (int i = 0; i <= n; i++)
           {
               for (int j = 0; j < i; j++)
               {
                   count++;
                   Console.Write(" " + count);
               }
               Console.Write("\n");
           }
       }


void Pattern(int rows)
{
    int startNumber = 1;
    for (int index = 1; index <= rows; index++)
    {
        for (int innerIndex = 1; innerIndex <= index; innerIndex++)
        {
            Console.Write("{0} ", startNumber++);
        }
        Console.WriteLine("");
    }
}


这篇关于金字塔形状中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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