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>

No comments:

Post a Comment