Monday, 6 March 2017

Fibonacci-series-In-JavaScript

Fibonacci numbers are the numbers in the accompanying whole number succession, called the Fibonacci series. In this Post, we will try to explain Fibonacci series in the different method. Hope You will Understand this program. any query you can comment below.  save all the files with (.HTML) extension.


 Fibonacci Series (1-10)


<html>
<body>
<script type="text/javascript">
var a=0,b=1,c;
document.write("Fibonacci");
while (b<=10)
{
document.write(c);
document.write("<br/>");
c=a+b;
a=b;
b=c;
}
</script>
</body>
</html>

Fibonacci series (input from user) 

<html>
 <head>
 <title>FibonacciSeries Using JavaScript</title>
 <script>
 function on_btn_gen_click() {
 count = parseInt(document.getElementById("in1").value);
 a = 0, b = 1, sum = 0;
 output = "<b>The first " + count + " elements in the Fibonacci series:</b> ";

 for(i = 0; i < count; i ++) {
 output += a + " ";
 sum = a + b;
 a = b;
 b = sum;
 }

 document.getElementById("p1").innerHTML = output;
 }
 </script>
 </head>
 <body bgcolor="LightGreen">
 <h1>Fibonacci Series</h1>
 <h2>Helps2code</h2>
 Enter the count of terms: <input id="in1" />
 <button id="btnGen" onclick="on_btn_gen_click()">ClickHere</button>
 <p id="p1" />
 </body>
</html>



0 comments:

Post a Comment