Logo 
Search:

C# Forum

Ask Question   UnAnswered
Home » Forum » C#       RSS Feeds

using text box

  Asked By: Srikanth    Date: Feb 07    Category: C#    Views: 982
  

print the numbers in the below format where n is user input from a text box . on the press of the button , the output should appear.
9999999999
999999999
99999999
9999999
999999
99999
9999
999
99
9

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Vivek Patel     Answered On: Feb 09

Take 3 controls on windows form 1) Textbox Control named textbox1 (For UserInput) 2) Button Control named button1 3) Label Control named lblOutput (For Output) Double click on button control and add following code for your button1_click event.


private void button1_Click(object sender, EventArgs e)
{            
    string UserInput = textBox1.Text;

    StringBuilder sbVertical = new StringBuilder();
    StringBuilder sbHorizontal = new StringBuilder();

    for (int i = 10; i > 0; i--)
    {
        sbHorizontal.Clear();
        for (int j = 0; j < i; j++)
        {
            sbHorizontal.Append(UserInput);
        }
        sbVertical.Append(sbHorizontal.ToString());
        sbVertical.Append("\n");
    }

    lblOutput.Text = sbVertical.ToString();
}

 
Didn't find what you were looking for? Find more on using text box Or get search suggestion and latest updates.




Tagged: