用C#判定一个三位数是不是水仙花数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   Console.Write("请输入一个三位数:");
   int n = int.Parse(Console.ReadLine());
   if (n < 100 || n > 999)
    {
     Console.WriteLine("输入有误");
    }
   else
    {
     int a = n / 100 % 10;
     int b = n / 10 % 10;
     int c = n % 10;
     if (a * a * a +b * b * b + c * c * c == n)
     {
      Console.WriteLine("你输入的是水仙花数");
     }
    else
     {
    Console.WriteLine("你输入的不是水仙花数");
    }
   }
   Console.ReadLine();
  }
 }
}

posted @ 2017-12-10 21:32  A谭智天  阅读(2650)  评论(0编辑  收藏  举报