"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如: 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; } }}
新闻热点
疑难解答