码迷,mamicode.com
首页 > 其他好文 > 详细

水仙花数

时间:2015-06-09 13:53:36      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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

        private void button1_Click(object sender, EventArgs e)
        {
            int a = 0, b = 0, c = 0;
            for (int i = 100; i < 1000; i++)
            {
                a = i / 100;
                Math.DivRem(i, 100, out b);
                b = b / 10;
                Math.DivRem(i, 10, out c);
                a = a * a * a;
                b = b * b * b;
                c = c * c * c;
                if ((a + b + c) == i)
                    listBox1.Items.Add(i.ToString());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

水仙花数

标签:

原文地址:http://blog.csdn.net/lucky51222/article/details/46425109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!