首页 > 技术文章 > 用c#语言编写水仙花数

yangkaiming 2018-04-09 19:19 原文

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

namespace ConsoleApplication1
  {
          class Program
           {
                  static void Main(string[] args)
                   {
                         for (int i = 100; i < 999; i++)
                         {
                                 int a = i / 100 % 10;
                                 int b = i / 10 % 10;
                                 int c = i % 10;
                                 if (a * a * a + b * b * b + c * c * c ==i)
                                 {
                                     Console.WriteLine(i);
                                  }

                          }
               }
      }
}

推荐阅读