Friday, 30 November 2012

PHP - Fibonacci Series

 The below is code to print Fibonacci Series.

<?php
$a = 0;
$b = 1;
$limit = 150;
print $a.' '.$b;
for($i=1; $i <= $limit; $i++) {
   $c = $a + $i;
   if($c > $limit) break;
   $a = $i;
   $i = ($c-1);
   print " ".$c;
}
?>

O/P: 0 1 1 2 3 5 8 13 21 34 55 89 144

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.