水仙花数的实现

//int 和int类型计算得到的结果还是int类型 eg:int a = 371 / 100 % 10。一 371除以100得到的是3,而不是3.71。二 再用3%10,求余为3

namespace 水仙花数
{
class Program
{
static void Main(string[] args)
{
//请输出1000以内的所有水仙花数
//指一个n位数(n>=3),153
Console.WriteLine("1000以内的所有水仙花数:");
for (int i = 100; i < 1000; i++)
{
int a = i / 100 % 10;//百位a
int b = i / 10 % 10; //十位b
int c = i % 10;//各位c
if (i==a*a*a+b*b*b+c*c*c)
{
Console.WriteLine(i);
}
}
Console.ReadLine();
}
}
}

猜你喜欢

转载自www.cnblogs.com/yt0817/p/11628917.html