用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();
  }
 }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM