php实现水仙花
程序员文章站
2022-05-02 23:09:34
...
class Armstrong {
static function index(){
for ( $i = 100; $i
echo self::is_armstrong($i) ? $i . '
' : '';
}
}
static function is_armstrong($num){
$s = 0;
$k = strlen($num);
$d = str_split($num);
foreach ($d as $r) {
$s += bcpow($r, $k);
}
return $num == $s;
}
}
Armstrong::index();
?>