首页 > 学院 > 开发设计 > 正文

求100-999之间的水仙花数

2019-11-08 01:44:37
字体:
来源:转载
供稿:网友

"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:  153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 水仙花数{    class PRogram    {        static void Main(string[] args)        {            for (int i = 100; i < 999; i++)            {                if (isTrue(i))                {                    Console.WriteLine("水仙花数:" + i.ToString());                }            }            Console.WriteLine("结束");            Console.ReadKey();        }        private static bool isTrue(int i)        {            //取个位            int a = i / 100;            int b = (i - a * 100) / 10;            int c = i - a * 100 - b * 10;            if (a*a*a+b*b*b+c*c*c==i)            {                return true;            }                        return false;        }    }}


上一篇:HDOJ 考新郎

下一篇:文件

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表