VB.Net的问题,输入整数n,显示具有n行的杨辉三角形。
答案:1 悬赏:30 手机版
解决时间 2021-01-25 05:43
- 提问者网友:遁入空寂
- 2021-01-24 10:08
VB.Net的问题,输入整数n,显示具有n行的杨辉三角形。
最佳答案
- 五星知识达人网友:往事隔山水
- 2021-01-24 11:11
参考:
以下为十行的杨辉三角输出,根据这个自己做相应修改,都做好了,那你就是伸手党了。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim n As Integer
n = 10
Dim dete(n, n) As Integer
Dim sum As Integer
For i = 0 To n
For j = 0 To i
If i = 0 Then
dete(i, j) = 1
ElseIf j = 0 Then
dete(i, j) = 1
ElseIf i = j Then
dete(i, j) = 1
Else
dete(i, j) = dete(i - 1, j - 1) + dete(i - 1, j)
End If
Next
Next
For i = 0 To n
For j = 0 To i
Debug.Write(dete(i, j) & " ")
sum += dete(i, j)
Next
Debug.WriteLine(" ")
Next
End Sub
End Class
以下为十行的杨辉三角输出,根据这个自己做相应修改,都做好了,那你就是伸手党了。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim n As Integer
n = 10
Dim dete(n, n) As Integer
Dim sum As Integer
For i = 0 To n
For j = 0 To i
If i = 0 Then
dete(i, j) = 1
ElseIf j = 0 Then
dete(i, j) = 1
ElseIf i = j Then
dete(i, j) = 1
Else
dete(i, j) = dete(i - 1, j - 1) + dete(i - 1, j)
End If
Next
Next
For i = 0 To n
For j = 0 To i
Debug.Write(dete(i, j) & " ")
sum += dete(i, j)
Next
Debug.WriteLine(" ")
Next
End Sub
End Class
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯