2个回答
展开全部
由vb编程可以这样写:
Private Sub Command1_Click()
Dim a
n = InputBox("输入行数")
ReDim a(n, n)
For i = 1 To n
For j = i To n
If i = j Then a(i, j) = 1
a(i, 1) = 1
Next j, i
For i = 2 To n
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 1 To n
For j = 1 To n
Print a(i, j); " ";
Next j
Print
Next i
End Sub
Private Sub Command1_Click()
Dim a
n = InputBox("输入行数")
ReDim a(n, n)
For i = 1 To n
For j = i To n
If i = j Then a(i, j) = 1
a(i, 1) = 1
Next j, i
For i = 2 To n
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 1 To n
For j = 1 To n
Print a(i, j); " ";
Next j
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
.. 以前有人提过这样的问题了: http://zhidao.baidu.com/question/116703115.html?oldq=1
我把以前写的拿过来修改了一下:
<html>
<head>
<script language="javascript">
var G=document.getElementById;
function Button_Click(){
var num = parseInt(G("txtInput").value);
var aryYang = DrowYangS(num);
//将结果输出到Div中
G("resultArea").innerHTML = (aryYang.join("<BR>")).replace(/,/g," ");
}
function DrowYangS(Rows){
var aryYang,aryRows,aryPreRows ;
aryYang = arguments[1] ? arguments[1] : [];
if (Rows == 1){
aryRows = [1];
}else{
DrowYangS(Rows-1,aryYang);
aryRows = [];
aryPreRows = aryYang[Rows-2];
aryRows.push(1);
for(var i = 0;i<aryPreRows.length-1;i++){
aryRows.push(aryPreRows[i] + (aryPreRows[i+1] ? aryPreRows[i+1] : 0));
}
aryRows.push(1);
}
aryYang[aryYang.length] = aryRows;
return aryYang;
}
</script>
</head>
<body >
<input type="text" id="txtInput">
<button onclick="Button_Click();"> 运行</button> <br>
<div id="resultArea"> </div>
</body>
</html>
我把以前写的拿过来修改了一下:
<html>
<head>
<script language="javascript">
var G=document.getElementById;
function Button_Click(){
var num = parseInt(G("txtInput").value);
var aryYang = DrowYangS(num);
//将结果输出到Div中
G("resultArea").innerHTML = (aryYang.join("<BR>")).replace(/,/g," ");
}
function DrowYangS(Rows){
var aryYang,aryRows,aryPreRows ;
aryYang = arguments[1] ? arguments[1] : [];
if (Rows == 1){
aryRows = [1];
}else{
DrowYangS(Rows-1,aryYang);
aryRows = [];
aryPreRows = aryYang[Rows-2];
aryRows.push(1);
for(var i = 0;i<aryPreRows.length-1;i++){
aryRows.push(aryPreRows[i] + (aryPreRows[i+1] ? aryPreRows[i+1] : 0));
}
aryRows.push(1);
}
aryYang[aryYang.length] = aryRows;
return aryYang;
}
</script>
</head>
<body >
<input type="text" id="txtInput">
<button onclick="Button_Click();"> 运行</button> <br>
<div id="resultArea"> </div>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询