C#实现1000以内的水仙花数

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 _03判断水仙花数
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int shui = int.Parse(textBox1.Text);

            int a = shui % 10;
            int b = (shui / 10) % 10;
            int c = shui / 100;
            if (a * a * a + b * b * b + c * c * c == shui)
            {
                label2.Text = shui.ToString() + "是水仙花数;";
                //直接输入1000以内的水仙花数
              // label2.Text + = shui.ToString() + ",";
            }
            else
            {
                label2.Text = shui.ToString() + "不是水仙花数;";
            }

        }

       
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43551373/article/details/85602614
今日推荐