标签:turn splay push tle [] class code asc data
斐波那契数列:1,1,2,3,5,8,....
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>斐波那契数列</title> <style type="text/css"> html,body{ padding: 0;margin: 0; width: 100%; height: 100%; } #res{ padding: 5px 20px;; } </style> </head> <body> <h1>求斐波那契数列中的第N项。</h1> <p> 斐波那契数列:1,1,2,3,5,8,.... </p> <div id="res"> <h2>第3/6/8/100项的结果:</h2> </div> <script type="text/javascript"> (function(window,document){ function displayRes(n){ var arr=[]; arr=getArr(n); var div=document.createElement("div"); var text=document.createTextNode(n>0?arr[n-1]:1); div.appendChild(text); document.getElementById("res").appendChild(div); } function getArr(n){ var arr=[1]; for(var i=1;i<n;i++){ var a=arr[i-1]|| 0,b=arr[i-2]||0; var data=a+b; arr.push(data); } return arr; } displayRes(3); displayRes(6); displayRes(8); displayRes(100); })(window,document) </script> </body> </html>
标签:turn splay push tle [] class code asc data
原文地址:http://www.cnblogs.com/mrGan/p/6497561.html