<html> <head> <title> 双击也可运行代码 </title> <style type="text/css"> </style> <script type="text/javascript"> /** 设一个数列,它的前四项为0,0,2,5,以后每项是分别是其前四项之和,编程求该数列前20项,并按四行五列输出前20项(一行输出五个)? */ /** * @author Chang * @E-mail Augustdp AT 126 DOT com * @date 2008-12-10 21:01:09 */ var dataArr = new Array(); var tmp = 0; dataArr.push(0); dataArr.push(0); dataArr.push(2); dataArr.push(5); //构造 for (i = 4; i < 20; i++) { tmp = dataArr[i - 4] + dataArr[i - 3] + dataArr[i - 2] + dataArr[i - 1]; dataArr.push(tmp); } //输出 var tbHTML = "<table>"; for (i = 0; i < 4; i++) { tbHTML += "<tr>"; for (j = 0; j < 5; j++) { tbHTML += "<td>" + dataArr[i * 4 + j] + "</td>"; } tbHTML += "</tr>"; } tbHTML += "</table>"; document.write(tbHTML); </script> </head> <body> <div class=""> </div> </body> </html>
格式化压缩 经典微软