C#基础:打印水仙花数

水仙花数是一个3位数,并且每一位上面数的立方和等于本身。

  1.             for (int i = 100; i < 1000; i++) {
  2.                 int a = i / 100;     //百位 123 / 100 = 1
  3.                 int b = i % 100 / 10;//十位 123 % 100 / 10 = 2
  4.                 int c = i % 10;      //个位 123 % 10 = 3
  5.                 if (a * a * a + b * b * b + c * c * c == i) {
  6.                     Console.WriteLine (i);
  7.                 }
  8.             }
  9.          
  10.             Console.ReadKey();

猜你喜欢

转载自blog.csdn.net/QQhelphelp/article/details/82956854
今日推荐