Showing posts with label Fibonacci. Show all posts
Showing posts with label Fibonacci. Show all posts

Friday, March 30, 2012

Fibonacci series using php.....

This code generates the fibonacci series upto n numbers.

<?php
$a=0;
$b = 1;
$n =20;
print $a.'<br>';
for($i=1;$i<$n;$i++)
   {
   $final = $a + $b;
   $a = $b;
   $b = $c;
   if($c<n)
  {
         break;
  }
   print $c.'<br>';
   }
?>

Thursday, March 15, 2012

Fibonacci Series

This javascript generates the fibonacci series upto the given number.
Following is the javascript for the sane:-


<html>
 <head>
    <title>Fibonacci Series</title>
</head>
 <body>
    <script language="javascript" type="text/javascript">
   

        var a = 0;
        var b = 1;
        var c;

        var num = prompt("Enter the limit to generate fibonacci no",0);

        document.write(a+"<br />");
        document.write(b+"<br />");

        for(var i=3; i <= num;i++)
        {
            c = a + b;
            a = b;
            b = c;

            document.write(c+"<br />");
        }

    // -->
    </script>

 </body>
</html>