输入一个正整数n0.
1-n之间的所有水仙花数
1000
153 370 371 407
using System;
namespace 第五题
{
class Program
{
static void Main(string[] args)
{
int n;
Console.Write("请输入数字:\t");
n = Convert.ToInt32(Console.ReadLine());
IsNarcissistic(n);
printN(n);
}
public static bool IsNarcissistic( int n)
{
int a, b = 0, c, sum = 0, d;
a = n;
d = n;
while (a != 0)
{
a /= 10;
b++;
}
while (n != 0)
{
c = n % 10;
sum += (int)Math.Pow(c, b);
n /= 10;
}
if (sum == d) return true;
else return false;
}
public static void printN( int n)
{
for (int i = 10; i < n; i++)
{
if (IsNarcissistic(i))
Console.WriteLine(i);
}
}
}
}