本文共 1591 字,大约阅读时间需要 5 分钟。
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 HomeTest006{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtIn.Text); int y = (x - 1) / 2; for (int a = 1; a <= y; a++) //打印菱形前一半 { for (int c = 1; c <= y - a + 1; c++) { lblOut.Text += Convert.ToString(" "); } for (int b = 1; b <= a; b++) { lblOut.Text += Convert.ToString("* "); } lblOut.Text += Convert.ToString("\n"); } for (int z = 1; z <= y + 1; z++) //打印中间行 { lblOut.Text += Convert.ToString("* "); } lblOut.Text += Convert.ToString("\n"); for (int a1 = y; a1 >= 1; a1--) //打印菱形后一半 { for (int c1 = 0; c1 <= y - a1; c1++) { lblOut.Text += Convert.ToString(" "); } for (int b1 = 1; b1 <= a1; b1++) { lblOut.Text += Convert.ToString("* "); } lblOut.Text += Convert.ToString("\n"); } } }}
转载地址:http://qwywi.baihongyu.com/