示例1:
复制代码 代码如下:
<?php
for($q=1;$q<=9;$q++){
for($w=0;$w<=9;$w++){
for($e=0;$e<=9;$e++){
if($q*$q*$q + $w*$w*$w + $e*$e*$e ==
100*$q + 10*$w + $e){
echo "$q $w $e "."<p>";
}
}
}
}
?>
示例2:
复制代码 代码如下:
<?php
function cube( $n )
{
return $n * $n * $n;
}
function is_narcissistic ( $n )
{
$hundreds = floor( $n / 100); //分解出百位
$tens = floor( $n / 10 ) % 10; //分解出十位
$ones = floor( $n % 10 ); //分解出个位
return (bool)(cube($hundreds)+cube($tens)+cube($ones) == $n);
}
for ( $i = 100; $i < 1000; ++ $i )
{
if ( is_narcissistic($i) )
echo $i."\n";
}
?>
示例3:
复制代码 代码如下:
<?php
//阿姆斯特朗数:一个k位数,它的每个位上的数字的k次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)
class Armstrong {
static function index(){
for ( $i = 100; $i < 100000; $i++ ) {
echo self::is_armstrong($i) ? $i . '<br>' : '';
}
}
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();
示例4:
复制代码 代码如下:
<html>
<head>
<title></title>
</head>
<body>
<?php
function winter($num)
{
if($num<1000){
//定义个位
$ge=$num%10;
//定义十位
$ten=(($num%100)-$ge) /10;
//定义百位
/*floor取整,忽略小数点后面的所有数*/
$hundred=floor($num/100);
$sum1=$ge*$ge*$ge+$ten*$ten*$ten+$hundred*$hundred*$hundred;
if($sum1==$num){
return 1;
} else{
return 0;
}
} else{
return -1;
}
}
if(winter(371)==-1) {
echo "大于1000的数";
}else{
if(winter(371)) {
echo "Yes";
}
else{
echo "No";
}
}
?>
</body>
</html>
php,水仙花数
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]