swift实现水仙花数

import Foundation
func f(a: Int) -> Int {
    var x = a
    x *= a
    x *= a
    return x
}
var a, b, c: Int
for x in 100...999 {
    a = x%10
    b = x/10%10
    c = x/100
    if x == f(a: a) + f(a: b) + f(a: c) {
        print(x);
    }
}

 

地址 http://sshpark.com.cn/
原文地址:https://www.cnblogs.com/huangjiaming/p/5697828.html