1. 程式人生 > >c#隨便輸入一個小於100000的數輸出他的每一位

c#隨便輸入一個小於100000的數輸出他的每一位

視窗:輸入一個數字點選確定時輸出每一位,點選清空時清空內容,要求這個數字小於100000
在這裡插入圖片描述
程式碼:

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 _06隨便輸入一個小於100000的數輸出他的每一位
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = int.Parse(textBox1.Text);
            if (i>0 && i<=100000)
            {
                int shiwan = i / 100000;
                textBox2.Text = shiwan.ToString();
                int wan = (i % 100000) / 10000;
                textBox3.Text = wan.ToString();
                int qian = (i % 10000) / 1000;
                textBox4.Text = qian.ToString();
                int bai = (i % 1000) / 100;
                textBox5.Text = bai.ToString();
                int shi = (i % 100) / 10;
                textBox6.Text = shi.ToString();
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
            if (i>0 &&i<=10000)
            {
                int wan = i / 10000;
                textBox3.Text = wan.ToString();
                int qian = (i % 10000) / 1000;
                textBox4.Text = qian.ToString();
                int bai = (i % 1000) / 100;
                textBox5.Text = bai.ToString();
                int shi = (i % 100) / 10;
                textBox6.Text = shi.ToString();
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
            if (i>0 && i<=1000)
            {
                int qian = i / 1000;
                textBox4.Text = qian.ToString();
                int bai = (i % 1000) / 100;
                textBox5.Text = bai.ToString();
                int shi = (i % 100) / 10;
                textBox6.Text = shi.ToString();
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
            if (i>0 && i<=100)
            {
                int bai = i / 100;
                textBox5.Text = bai.ToString();
                int shi = (i % 100) / 10;
                textBox6.Text = shi.ToString();
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
            if (i>0 && i<=10)
            {
                int shi = i / 10;
                textBox6.Text = shi.ToString();
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
            if(i>0 && i < 10)
            {
                int ge = (i % 10);
                textBox7.Text = ge.ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
        }
    }
}