zoukankan      html  css  js  c++  java
  • 自娱自乐的小题目(3)

    题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:
    153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

    这个题目我发现我写的有点2= =

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Test3 {
        class Program {
            //题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:
            //153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
            static void Main(string[] args) {
                int a, b, c, e, d, f, sum;
                for (int i = 100; i < 1000; i++) {
                    a = (int)i / 100;
                    b = (int)(i - a * 100) / 10;
                    c = (int)(i - a * 100 - b * 10);
                    d = (int)Math.Pow(a, 3);
                    e = (int)Math.Pow(b, 3);
                    f = (int)Math.Pow(c, 3);
                    sum = d + e + f;
                    if (d + e + f == i) {
                        Console.WriteLine(i);
                    }
                }
            }
        }
    }

     

  • 相关阅读:
    Window 中的自带方法Base64
    React_Class1
    npm 常用操作
    React__生命周期
    axios 简单方法个人理解
    JavaScript_Window对象
    常见的搜索引擎技巧
    JS_String常见问题Demo
    java调用C++代码
    java虚拟机指令dup的理解
  • 原文地址:https://www.cnblogs.com/socialdk/p/2519181.html
Copyright © 2011-2022 走看看