Posted By

iamdezzy on 02/24/11


Tagged

math numbers mathematics narcissistic


Versions (?)

Function for Finding Narcissistic Numbers


 / Published in: PHP
 

I'm just trying

  1. <?php
  2. $number = 1;
  3. $lastnumber = 2800;
  4. function find($x){
  5. settype($x, "string");
  6. $u=strlen($x);
  7. if($u == 1){
  8. return $x;
  9. }
  10. return bcpow($x[$u-1],$u) + find(floor($x/10));
  11. }
  12.  
  13. for($a=1;$a<$lastnumber;$a++){
  14. $result = find($number);
  15. if($result == $number){
  16. echo $number."<br/>";
  17. }
  18. $number++;
  19. }
  20. ?>

Report this snippet  

You need to login to post a comment.