Function for Finding Narcissistic Numbers


/ Published in: PHP
Save to your folder(s)

I'm just trying


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.