首页 > Windows开发 > 详细

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

时间:2017-12-10 22:20:28      阅读:333      评论:0      收藏:0      [点我收藏+]

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#判定一个三位数是不是水仙花数

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!