C#實現1000以內的水仙花數
阿新 • • 發佈:2019-01-08
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() + "不是水仙花數;"; } } } }