1. 程式人生 > >C#實現100到100000以內的迴文數

C#實現100到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 _01迴文數
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "";
            for (int i = 100; i < 100000; i++)
            {
                int a = i / 10000;
                int b = i % 10000 / 1000;
                int c = i % 1000 / 100;
                int d = i % 100 / 10;
                int g = i % 10;
                if (i<1000 &&i>100 && c==g)
                {
                    label1.Text = label1.Text+i.ToString() + "\r\n";
                }
                if (i<10000 && i>1000 && b==g && c==d)
                {
                    label1.Text = label1.Text + i.ToString() + "\r\n";
                }
                if (i<100000 && i>10000 && a==g && b==d)
                {
                    label1.Text = label1.Text + i.ToString() + "\r\n";
                }
            }
        }
    }
}