<html>
<script language="javascript">
<!--
function f( v )
{   
    //if ( v == 0 || v == 1 ) {
    if ( v < 2 ) {
        return v;
    } else { 
        return f( v - 1 ) + f( v - 2 );
    }
}

var n = window.prompt("請輸入數字:(遞迴 0 ~ n 項)","");

document.write("<table border=1 cellspacing=2 cellpadding=3>");
document.write("<tr align=center>");
for (var i = 0; i <= n; i++)
{
    document.write( "<td width=30><b>" + (i+1) + "</b></td>");
}
document.write("</tr><tr align=center>");
for (var i = 0; i <= n; i++)
{
   // document.write( f( i ) + " ");
    document.write( "<td width=30>" + f( i ) + "</td>");
}
document.write("</tr>");
document.write("</table>");
//-->
</script>
</html>

創作者介紹

程式。生活錄

ㄡ ㄋㄧ' ㄦ 發表在 痞客邦 PIXNET 留言(0) 人氣()