Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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/>");
 
        }
 
 
please help me.
Posted 10-Jul-13 20:17pm
Edited 11-Jul-13 1:27am
v2
Comments
Sushil Mate at 11-Jul-13 1:56am
   
Homework?
Rate this: bad
good
Please Sign up or sign in to vote.

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");
 
     }
 
     Console.ReadLine();
 
       }
  Permalink  
Comments
Member 9567873 at 11-Jul-13 2:24am
   
Please give in asp.net
Rate this: bad
good
Please Sign up or sign in to vote.

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();
 
            }
            Console.ReadLine();
        }
 
Accept as answer if solve you problem.
  Permalink  
Comments
Member 9567873 at 11-Jul-13 2:24am
   
please give in asp.net.
Member 9567873 at 11-Jul-13 2:46am
   
the code is giving a different output.
Member 9567873 at 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 at 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");
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100