水仙花数:是指一个数每一位上的数字的立方和等于该数本身 .
窗口:
在这里插入图片描述
点击按钮时输出0-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_判断0_1000之间的水仙花数
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = 100;
            label2.Text = "";
            for (;i<1001;i++)
            {
                int a, b, c;
                a = i % 10;
                b = (i / 10) % 10;//b=(i%100)/10;
                c = i / 100;
                if (a * a * a + b * b * b + c * c * c == i)
                {
                    label2.Text = label2.Text + i.ToString() + ",";
                }
                
            }
           
        }
    }
}

在这里插入图片描述

posted on 2019-01-01 11:27  豆皮没有豆  阅读(277)  评论(0)    收藏  举报