fibonacci.php 370 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
#!/usr/bin/env php

<?php

if(! isset($argv[1]) || ! is_numeric($argv[1]) || intval($argv[1]) <= 0){
printf("Usage: %s nbr_int
nbr_int: Un nombre entier supérieur à 0\n", $argv[0]);
exit(1);
}

$nbr_int = intval($argv[1]);

$a = 0;
$b = 1;

while ($b < $nbr_int) {
printf("%d\n", $b);
$b = $a + $b;
$a = $b - $a;
}

printf("b/a = %1.15f\n", $b/$a);

exit(0);