印刷金字塔的traingles [英] printing pyramid of traingles

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

问题描述

下午好



i的任务是以两种不同的形式打印数字。



First ,如果我给出值5,结果应该是

******** 1

******* 2 3

****** 4 5 6

***** 7 8 9 10

*** 11 12 13 14 15



秒,如果我给出值5,结果应该是



1

2 3

4 5 6

7 8 9 10



i我正在编写第一个代码为



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;

public partial class Pyramid:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
}
protected void btnsubmit_Click( object sender,EventArgs e)
{
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( ķ++);
}

Response.Write( \ n );
}
}
}





请帮帮我

解决方案

这有很多问题,但由于你没有告诉我们你没有问题,我们可以从最基本的开始:

 Response.Write(  k ++); 



也许如果你删除引号会有帮助吗?

 Response.Write(k ++ ); 

那么,我们只修复其他内容:这是一个网站,所以\ n不起作用。尝试

 Response.Write( < br / >中); 

相反...


good afternoon

i have a task of printing the numbers in two different forms.

First, if i give a value of 5 the result should be
******** 1
******* 2 3
****** 4 5 6
***** 7 8 9 10
*** 11 12 13 14 15

second, if i give a value of 5 the result should be

1
2 3
4 5 6
7 8 9 10

i am writing the code for first one as

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pyramid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        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("\n");
        }
    }
}



please help me

解决方案

There are a number of things wrong with this, but since you don't tell us what problem you notioced, we can start with the most basic:

Response.Write("k++");


perhaps if you remove the quotes it would help?

Response.Write(k++);

Then, let's just fix something else as well: This is a web site, so "\n" won't work. Try

Response.Write("<br />");

Instead...


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

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