JavaScript Program to Print up to Nth Place of Fibonacci series

print-nth-place-fibonacci-series-javascript-program-decoderp

JavaScript code

<HTML>
  <HEAD>
    <TITLE>
    </TITLE>
  </HEAD>
  <BODY>
    <SCRIPT>
      var a=0,b=1,c,i;
      var n=prompt("Enter up to nth place :");
      document.write(a+b);
      for(i=0;i<=n;i++)
      {
       c=a+b;
       a=b;
       b=c; 
       document.write("\t"+c);
      }
    </SCRIPT>
  </BODY>
</HTML>

Output :

Enter up to nth place :
5
1 1 2 3 5 8 13

Post a Comment

0 Comments