HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
fibonacci number code in php

<?php
function fibonacci($n)
{
$a = 1;
$b = 1;
for ($i = 0; $i < $n; $i=$i+1)
{
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.$a;
$sum = $a+$b;
$a = $b;
$b = $sum;
}
}
echo fibonacci(20);
?>

Output comes like:

1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765

   Share on Facebook

Page views:1048