"水仙花數"是指一個三位數,其各位數字立方和等于該數本身。例如: 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; } }}
新聞熱點
疑難解答