k-c#

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication3

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void textBox2_TextChanged(object sender, EventArgs e)

{

int i, j, k, max, min;

min = Convert.ToInt32(textBox1.Text);

max = Convert.ToInt32(textBox2.Text);

string _star, _space;

label1.Text = label2.Text = "";

_star = "*";

_space = " ";

try

{

min = Convert.ToInt32(textBox1.Text);

max = Convert.ToInt32(textBox2.Text);

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

{

label1.Text += i.ToString(); //第一題

for (j = max - i - 1; j >= 0; j--)

{

label1.Text += _space; //第一題

}

for (k = 1; k <= 2 * i - 1; k++)

{

if (i >= min)

label1.Text += _star; //第一題

}

label1.Text += "\n";//第一題

}

//===============第二題==================================================

_star = " ";

_space = "*";

for (k = 1; k <= 2 * max + 1; k++)

label2.Text += _space;

label2.Text += "\n";

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

{

for (j = max - i; j >= 0; j--)

{

label2.Text += _space;

}

for (k = 1; k <= 2 * i - 1; k++)

{

label2.Text += _star;

}

for (j = max - i; j >= 0; j--)

{

label2.Text += _space;

}

label2.Text += "\n";//第一題

}

for (i = max - 1; i >= 0; i--)

{

for (j = max - i; j >= 0; j--)

{

label2.Text += _space;

}

for (k = 1; k <= 2 * i - 1; k++)

{

label2.Text += _star;

}

for (j = max - i; j >= 0; j--)

{

if(j !=0 | i!=0)

label2.Text += _space;

}

label2.Text += "\n";//第一題

}

//===============END OF 第二題==================================================

}

catch { }

}

}

}