# 三角形程序

写来写去，最后还是回到原点！来介绍点最基础的东西——三角形！

灵活运用三角形是可以解决很多问题的！今天主要介绍如果形成三角形数组：

1、左三角形

private void 左三角形button_Click(object sender, EventArgs e)

{

//i表示X方向，j表示Y方向

int i, j, number = 0;

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

{

for (j = i; j < 10; j++)

{

number++;

Graphics gp = pictureBox.CreateGraphics();

Brush drawBrush = new SolidBrush(Color.Blue);

Font font = new Font("Times New Roman", 10, FontStyle.Regular);

gp.DrawString(number.ToString(), font, drawBrush, i * 15, j * 15 );

}

}

}

2、右三角形

private void 右三角形button_Click(object sender, EventArgs e)

{

//i表示X方向，j表示Y方向

int i, j, number = 0;

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

{

for (j = 10 - i; j < 10; j++)

{

number++;

Graphics gp = pictureBox.CreateGraphics();

Brush drawBrush = new SolidBrush(Color.Blue);

Font font = new Font("Times New Roman", 10, FontStyle.Regular);

gp.DrawString(number.ToString(), font, drawBrush, i * 15, j * 15 );

}

}

}

3倒左三角形

private void 倒左三角形button_Click(object sender, EventArgs e)

{

//i表示X方向，j表示Y方向

int i, j, number = 0;

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

{

for (j = 1; j < 10-i; j++)

{

number++;

Graphics gp = pictureBox.CreateGraphics();

Brush drawBrush = new SolidBrush(Color.Blue);

Font font = new Font("Times New Roman", 10, FontStyle.Regular);

gp.DrawString(number.ToString(), font, drawBrush, i * 15, j * 15);

}

}

}

4倒右三角形

private void 倒右三角形button_Click(object sender, EventArgs e)

{

//i表示X方向，j表示Y方向

int i, j, number = 0;

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

{

for (j = 0; j < i ; j++)

{

number++;

Graphics gp = pictureBox.CreateGraphics();

Brush drawBrush = new SolidBrush(Color.Blue);

Font font = new Font("Times New Roman", 10, FontStyle.Regular);

gp.DrawString(number.ToString(), font, drawBrush, i * 15, j * 15);

}

}

}

5、按要求排序

7

4  8

2  5  9

1  3  6  10

private void 按要求排序button_Click(object sender, EventArgs e)

{

//i表示X方向，j表示Y方向

int i, j, number = 0;

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

{

for (j = 5 - i; j < 5; j++)

{

number++;

Graphics gp = pictureBox.CreateGraphics();

Brush drawBrush = new SolidBrush(Color.Blue);

Font font = new Font("Times New Roman", 10, FontStyle.Regular);

gp.DrawString(number.ToString(), font, drawBrush, (i+j-5) * 15, j * 15);

}

}

}