Write program in JavaScript to print Fibonacci series up to 15 Observations
Fibonacci series in
JavaScript
var limit = prompt("Enter the limit 'n' to generate the Fibonacci series:", " ");
var f1=0;
var f2=1;
document.write("The limit entered to generate the Fibonacci series is: ",limit, "<br/>");
document.write("The Fibonacci series is: ");
document.write("",f1," ");
document.write("",f2," ");
var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("",f3,", ");
f1=f2;
f2=f3;
}
OutPut :
The limit entered to generate the Fibonacci series is: 20
The Fibonacci series : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 The limit entered to generate the Fibonacci series is: 15
The Fibonacci series : 0 1 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
The Fibonacci series : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 The limit entered to generate the Fibonacci series is: 15
The Fibonacci series : 0 1 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
Comments
Post a Comment