码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-12-10 22:59:02      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:write   console   ext   c#   app   sys   ogr   eric   ace   

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

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

标签:write   console   ext   c#   app   sys   ogr   eric   ace   

原文地址:http://www.cnblogs.com/qwe32100/p/8018255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!