for循環例題

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 練習
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        //*****
        //*****
        //*****
        //*****
        //*****
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    textBox1.Text += "*";

                }
                textBox1.Text += "\r\n";
            }

        }
        //*
        //**
        //***
        //****
        //***** 
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //   *****
        //   ****
        //   ***
        //   **
        //   *

        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j <= 5 - i - 1; j++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //         *
        //        **
        //       ***
        //      ****
        //     *****
        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5 - i - 1; j++)
                {
                    textBox1.Text += " ";
                }
                for (int z = 0; z <= i; z++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //        *****
        //         ****
        //          ***
        //           **
        //            *
        private void button5_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    textBox1.Text += " ";
                }
                for (int z = 0; z <= 5 - i - 1; z++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //        *****             
        //         *****            
        //          *****           
        //           *****          
        //            *****
        private void button6_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    textBox1.Text += " ";
                }
                for (int z = 0; z < 5; z++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //          *           
        //         ***           
        //        *****           
        //       *******          
        //      ********* 
        private void button7_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5 - i - 1; j++)
                {
                    textBox1.Text += " ";
                }
                for (int z = 0; z <= i + i; z++)
                {
                    textBox1.Text += "*";
                }
                textBox1.Text += "\r\n";
            }
        }
        //        *****                
        //         *    *           
        //          *    *          
        //           *    *         
        //             *****   
        private void button8_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    textBox1.Text += " ";
                }
                for (int z = 0; z < 5; z++)
                {
                    if (i == 0 || i == 4)
                    {
                        textBox1.Text += "*";
                    }
                    else
                    {
                        textBox1.Text += ((z == 0 || z == 4) ? "*" : " ");

                    }
                }
                textBox1.Text += "\r\n";
            }
        }
      //     *
      //    ***
      //   *****
      //  *******
      // *********
      //  *******
      //   *****
      //    ***
      //     *
        private void button9_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                if (i<5)
                {
                    for (int j = 0; j < 5 - i - 1; j++)
                    {
                        textBox1.Text += " ";
                    }
                    for (int z = 0; z <= i + i; z++)
                    {
                        textBox1.Text += "*";
                    }
                    textBox1.Text += "\r\n";
                }
                else
                {
                    for (int j = 0; j < i - 4; j++)
                    {
                        textBox1.Text +=" ";
                    }
                    for (int z = 0; z < (9 - i) * 2 - 1; z++)
                    {
                        textBox1.Text += "*";
                    }
                    textBox1.Text += "\r\n";
                }                           
            }
        }
        //九九乘法表
        private void button10_Click(object sender, EventArgs e)
        {
            int[] sss = new int[5] {1,2,3,4,5};
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                  textBox1.Text+=(j + "*" + i + "=" + i * j + "\t");
                }
                textBox1.Text += "\r\n";
            }
        }
    }
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章