12,065,720 members (33,571 online)
Rate this:
See more:
good morning

i have task to print the nos in the pyramid format.

i.e if i give 3 means the output should be

space1
2space3
.
.
.

i wrote the code

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

int i, j, k;

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

}
```

Posted 10-Jul-13 20:17pm
Edited 11-Jul-13 1:27am
v2
Sushil Mate 11-Jul-13 1:56am

Homework?

Rate this:

Solution 1

Try this:

```static void Main(string[] args)
{
int i,j,k=1;

for (i=1; i<=2; i++)

{

for (j=1; j<i+1; j++)

{

Console.Write(k++ + " ");

}

Console.Write("\n");

}

}```
Member 9567873 11-Jul-13 2:24am

Rate this:

Solution 2

```try this one,..

static void Main(string[] args)
{

int numberoflayer = 6, Space, Number;

Console.WriteLine("Print paramid");

for (int i = 1; i <= numberoflayer; i++) // Total number of layer for pramid
{

for (Space = 1; Space <= (numberoflayer - i); Space++)  // Loop For Space

Console.Write(" ");

for (Number = 1; Number <= i; Number++) //increase the value

Console.Write(Number);

for (Number = (i - 1); Number >= 1; Number--)  //decrease the value

Console.Write(Number);

Console.WriteLine();

}
}

Accept as answer if solve you problem.```
Member 9567873 11-Jul-13 2:24am

Member 9567873 11-Jul-13 2:46am

the code is giving a different output.
Member 9567873 11-Jul-13 4:25am

i have changed the code like this

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

for (i = 1; i <= n; i++)
{
for (space = 1; space < n; space++)
{
Response.Write(" ");
}
for (n = 1; n < space; n--)
{
Response.Write("n");
}
}

then also it is not working
Member 9567873 11-Jul-13 6:33am

i have again changed the code like this. but then also it is not working.

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

int i, j, k, space;

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

for (i = 1; i <= n; i--)
{
for (space = 1; space < n; space++)
{
Response.Write(" ");
}
for (n = 1; n < space; n++)
{
Response.Write("n");
}
}

Top Experts
Last 24hrsThis month
 OriginalGriff 240 RDBurmon 100 CPallini 60 Sergey Alexandrovich Kryukov 49 ppolymorphe 40
 Dave Kreskowiak 1,841 Richard MacCutchan 1,260 OriginalGriff 1,114 d@nish 980 CPallini 810