js打印杨辉三角
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function yanghui(row){
//创建一维数组
var array=new Array(row);
//创建二维数组
for(var i=0;i<array.length;i++) {
array[i] = new Array(i + 1);
}
for(var i=0;i<array.length;i++){
for(var j=0;j<array[i].length;j++){
//array[i][j]=1;
if(j==0||i==j){
array[i][j]=1;
}else{
array[i][j]=array[i-1][j-1]+array[i-1][j];
}
}
}
for(var i=0;i<array.length;i++){
for(var j=0;j<array[i].length;j++){
document.write(array[i][j]+"\t");
}
document.write("<br/>");
}
}
yanghui(10);
</script>
</head>
<body>
</body>
</html>