zoukankan      html  css  js  c++  java
  • 水仙花数

    打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数

    本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace 水仙花算法 {
     7     class Program {
     8         static void Main ( string[ ] args ) {
     9             int start = 100;
    10             int end =1000;
    11             while ( start<end ) {
    12                 start++;
    13                 string str = start.ToString ( );
    14                 int x = Convert.ToInt32 ( str[0].ToString ( ) );
    15                 int y = Convert.ToInt32 ( str[1].ToString ( ) );
    16                 int z = Convert.ToInt32 ( str[2].ToString ( ) );
    17                 if ( ( Math.Pow ( x, 3 ) + Math.Pow ( y, 3 ) + Math.Pow ( z, 3 ) ) == start ) {
    18                     Console.WriteLine ( start );
    19                 }
    20             }
    21             Console.ReadKey ( );
    22         }
    23     }
    24 }
  • 相关阅读:
    foreach
    if
    注意事项
    Maven测试
    课程评价
    个人总结
    HTML表格CSS美化
    让多个输入框对齐
    CSS样式写在JSP代码中的几种方法
    日常
  • 原文地址:https://www.cnblogs.com/xiaoyu5062/p/2568937.html
Copyright © 2011-2022 走看看