What is the daffodil number in php

藏色散人
Release: 2023-02-24 08:08:02
Original
5908 people have browsed it

What is the daffodil number in php

phpWhat is the number of daffodils?

The so-called "daffodil number" refers to an n-digit number (n≥3), the sum of the nth power of the numbers in each digit is equal to itself.

PHP program for finding the number of daffodils, there are many ways to write it:

Method Example 1:

1000以内的水仙花数: 

'; for ( $i = 100; $i < 1000; ++ $i ) { $hundreds = floor( $i / 100); //分解出百位 $tens = floor( $i / 10 ) % 10; //分解出十位 $ones = floor( $i % 10 ); //分解出个位 if (bcpow($hundreds,'3')+bcpow($tens,'3')+bcpow($ones,'3') == $i) echo $i.""; } ?>
Copy after login

Output:

1000以内的水仙花数: 153 370 371 407
Copy after login

Method example two:

"; } } } }
Copy after login

Output:

153 370 371 407
Copy after login

Method example three:


        
Copy after login

Method example four :

' : ''; } } 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();
Copy after login

Output:

153 370 371 407 1634 8208 9474 54748 92727 93084
Copy after login

Method example five:

   
Copy after login

Output:

Yes
Copy after login

Related recommendations: "PHP Tutorial

The above is the detailed content of What is the daffodil number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!