fibonacci.php

  1. <?php
  2. // GMP = GNU Multiple Precision
  3.  
  4. function fibonacci($count) {
  5. show($index=1, $a=0);
  6. show($index=2, $b=1);
  7. while($index++ < $count) {
  8. $sum = gmp_add($a, $b);
  9. show($index, gmp_strval($sum));
  10. $a = $b;
  11. $b = $sum;
  12. }
  13. }
  14. function show($num, $value) {
  15. echo "<div><var>$num:&nbsp;</var><strong>$value</strong></div>\n";
  16. }
  17.  
  18. ?><!DOCTYPE html>
  19. <html>
  20. <head>
  21. <meta charset="utf-8">
  22. <title>Fibonacci</title>
  23. <style>
  24. h1 { text-align:center; }
  25. section {
  26. margin: 0 auto;
  27. }
  28. div {
  29. display:flex;
  30. justify-content: space-between;
  31. }
  32. div:nth-child(even) { background-color:#eee; }
  33. div:hover { background-color:gold; }
  34. </style>
  35. </head>
  36. <body>
  37. <h1>SucesiĆ³n de Fibonacci</h1>
  38. <section>
  39. <?php fibonacci(1000); ?>
  40. </section>
  41. </body>
  42. </html>
  43.  

Proinf.net