用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