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);
                    }
                }
            }
        }
    }

     

  • 相关阅读:
    HDU 1978 How many ways
    hdu 1966 Pie
    hdu 1966 Pie
    HDU 1896 Stones
    HDU 1896 Stones
    hdu 1278 逃离迷宫
    hdu 1278 逃离迷宫
    HDU 2548 A strange lift
    HDU 2548 A strange lift
    PHP 错误与异常 笔记与总结(10)错误处理器测试
  • 原文地址:https://www.cnblogs.com/socialdk/p/2519181.html
Copyright © 2011-2022 走看看