// 在控制台输出100—999 之间的水仙花数:如 只存在于百位数字之中,如果这个百位数字的百位的立方加上十位的立方加上各位的立方等于
//当前这个百位数字的话,则这个数字为水仙花数。例:153就是一个水仙花数,1*1*1+5*5*5+3*3*3=153
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 水仙花数
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入一个100-999之间的数n:");
int n = Int32.Parse(Console.ReadLine());
int k = 0;
for (int m = 100; m < n; m++)
{
if (Isnarcissistic(m))
{
Console.Write(m + ",");
k += 1;
if (k % 10 == 0)
{
Console.Write("\r\n");
}
}
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Exception message", ex);
}
}
static bool Isnarcissistic(int n) // 判断是否为水仙花数
{
int a = (int)n / 100;
int b = (int)(n % 100 / 10);
int c = (int)(n % 10);
if (a * a * a + b * b * b + c * c * c != n)
{
return false;
}
return true;
}
}
}
//当前这个百位数字的话,则这个数字为水仙花数。例:153就是一个水仙花数,1*1*1+5*5*5+3*3*3=153
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 水仙花数
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入一个100-999之间的数n:");
int n = Int32.Parse(Console.ReadLine());
int k = 0;
for (int m = 100; m < n; m++)
{
if (Isnarcissistic(m))
{
Console.Write(m + ",");
k += 1;
if (k % 10 == 0)
{
Console.Write("\r\n");
}
}
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Exception message", ex);
}
}
static bool Isnarcissistic(int n) // 判断是否为水仙花数
{
int a = (int)n / 100;
int b = (int)(n % 100 / 10);
int c = (int)(n % 10);
if (a * a * a + b * b * b + c * c * c != n)
{
return false;
}
return true;
}
}
}