Write a complete webpage with HTML and JavaScript at document
level.
1) Read row and column number with prompt() function with proper
exlanation.
2) Calculate first row * column Fibonacci numbers. Assume the
Fibonacci sequence starts
with 1 and 1.
3) Display all first row * column Fibonacci numbers in a HTML table
with row and column as
row and column numbers respectively. From 1, these number should be placed in ascending order from top to bottom in the table. In each row, the numbers should be placed from left to right.
Here is the answer...
CODE:
<!DOCTYPE html>
<html>
<head>
<title>fibo</title>
<script type="text/javascript">
function recursive_fibo(n)
{
if(n==0 ||
n==1)
{
return 1;
}
else
{
return
recursive_fibo(n-1)+recursive_fibo(n-2);
}
}
function fibo()
{
var row =
parseInt(window.prompt("enter row number"));
//read row
number
var column =
parseInt(window.prompt("enter column number"));
//read column number
var i=0;
var l=[];
for(i;i<row*column;i++)
//iterate through numbers
{
l.push(recursive_fibo(i));
//calling
recursive fibonocci with the numbers
}
//alert(row);
//alert(column);
//alert(l);
var x="";
x=x+"<table
style=\"border:1px solid;\">";
//creating table tag
var k=0;
for(var
i=0;i<row;i++)
{
x=x+"<tr>";
//creating tr tagt
for(var j=0;j<column;j++)
{
x=x+"<td
style=\"border:1px solid;
padding:20px;\">"+l[k++]+"</td>"; //push the
fibonocci numbers into td
}
x=x+"</tr>";
}
x=x+"</table";
document.getElementById("table").innerHTML=x;
}
</script>
</head>
<body onload="fibo()">
<div id="table"></div>
</body>
</html>
CODE Snapshot:
OUTPUT:
IF you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP..
Get Answers For Free
Most questions answered within 1 hours.