水仙花数:是指一个数每一位上的数字的立方和等于该数本身 .
窗口:
点击按钮时输出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() + ",";
}
}
}
}
}