Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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
Posted

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

C#
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");
           }
       }
 
Share this answer
 
C#
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("");
    }
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900