Code:
<!DOCTYPE html>
<html>
<body>
<center><h1>First N Fibonacci Numbers</h1>
<script>
var fib1=0,fib2=1,fib3,num,count=0;
var nl="<br>";
num=prompt("Enter the limit");
document.write(fib1+nl);
document.write(fib2+nl);
count=2;
while(count<num)
{
fib3=fib1+fib2;
count++;
document.write(fib3+nl);
fib1=fib2;
fib2=fib3;
}
</script>
</center>
</body>
</html>
No comments:
Post a Comment