水仙花数

来源:互联网 发布:高清机顶盒mac地址修改 编辑:程序博客网 时间:2024/03/29 00:21

原文及代码附件地址:http://www.dingos.cn/index.php?topic=1831.0

在数论中,水仙花数是指这样一个数,其各个数之立方和等于该数。

例如: 13 + 53 + 33 = 153。
十进制中的这样的数有:0、1、153、370、371、407,……
三进制中的这样的数有:0、1、2、12、122
四进制中的这样的数有:0、1、2、3、313

 

打印出100 ~ 999之间的所有“水仙花数”

using System;
public class NarcissusNumber{
    public static void Main(){
        for(int i = 100; i <= 999; i++){
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 100;

            if(i == (ge * ge * ge) + (shi * shi * shi) + (bai * bai * bai))
                Console.Write(i + "/t");
        }
        Console.ReadLine();
    }
}