博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#在Windows窗口用“*”打印菱形
阅读量:3937 次
发布时间:2019-05-23

本文共 1591 字,大约阅读时间需要 5 分钟。

C#在Windows窗口用“*”打印菱形

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/

你可能感兴趣的文章
Lesson2.2 & 2.3 Maya command reference & quick help
查看>>
lesson 2.4 - Converting MEL Commands to Python
查看>>
Lesson3.2 variables
查看>>
3.4.2 - Operators & 3.4.3 division and truncation
查看>>
3.7.1 - Strings
查看>>
3.7.4 - Indexing and Slicing Strings
查看>>
3.7.5 - Modifying Strings
查看>>
3.7.6 - String Methods
查看>>
3.8 - Using the Print Function
查看>>
3.9.1 - Lists in Python
查看>>
3.9.2 - Lists - Adding and Removing Objects
查看>>
3.9.3 - Sorting Lists
查看>>
3.10 - Maya Commands: ls
查看>>
3.11 - Dictionaries in Python
查看>>
3.12 - Tuples in Python
查看>>
4.4 - For Loops
查看>>
4.2.2 - Logical and/or Operators
查看>>
Lesson 4 Part 2 Softmax Regression
查看>>
文章中运用到的数学公式
查看>>
Projective Dynamics: Fusing Constraint Projections for Fast Simulation
查看>>