Algorithm-Test/水仙花数字/Program.cs

32 lines
998 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("100到999之内的水仙花数为: ");
for (int i = 100; i < 1000; i++)
{
//int a = i / 100;
//int b = (i - a * 100) / 10;
//int c = i - a * 100 - b * 10;
int a = i / 100; //百位数字
int b = i % 100 / 10; //十位数字
int c = i % 10; //个位数字
if (i == a * a * a + b * b * b + c * c * c)
{
Console.WriteLine("{0}*{0}*{0} + {1}*{1}*{1} + {2}*{2}*{2} = {3}", a, b, c, i);
}
}
Console.WriteLine("按任意键退出...");
Console.ReadLine();
}
}
}