asp.net - A pyramid using backward and forward slashes -
how can write program take integer input base width of pyramid , make appear this:
thanks!
aspx:
width:<asp:textbox id="textbox1" runat="server"></asp:textbox> <asp:button id="button1" runat="server" onclick="button1_click1" text="show pyramid" /> <br /><br /> <asp:label id="label1" runat="server"></asp:label>
code behind:
protected void button1_click1(object sender, eventargs e) { label1.text = ""; int width = int.parse(textbox1.text); int widthbetween = 4; int firstspace = 5 + width - 1; (int k = 0; k < firstspace + 2; k++) { label1.text+=" "; } label1.text += "^<br>"; (int = 0; < width; i++) { (int j = 0; j < firstspace; j++) { label1.text += " "; } label1.text += "/"; (int m = 0; m < widthbetween; m++) { if (i == width - 1) { if (m > (widthbetween / 2 - 1)) break; label1.text += "_"; } else { label1.text += " "; } } label1.text += @"\<br>"; widthbetween += 2; firstspace--; } }
Comments
Post a Comment