杨辉三角vb.net 杨辉三角形c语言程序

VB.net打印十阶杨辉三角代码

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

Debug.WriteLine(" 所有数的和:" sum)

End Sub

End Class

用vb.net2008打印杨辉三角形(打印10行),要求如图所示?

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim n As Integer, i As Integer, j As Integer, a(,) As Integer

n = 10

ReDim a(n + 1, n + 1)

For i = 1 To n + 1

a(i, 1) = 1 : a(i, i) = 1 : Next i

For i = 3 To n + 1

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 + 1

For j = 1 To i

TextBox1.AppendText(Space(4 - Len(Trim(Str(a(i, j))))) Trim(Str(a(i, j))))

Next j

TextBox1.AppendText(vbCrLf)

Next i

End Sub

End Class,9,

xixihahano1 举报

谢谢了,但是你写的代码可以输出多少行?多久会溢出了

举报 ccddty

没试过,你可以试试,将n的值加大 当n》16的时候就显示“参数“Number”必须大于或等于 0。”了 有没有办法解决?,

VB.Net的问题,输入整数n,显示具有n行的杨辉三角形。

参考:

以下为十行的杨辉三角输出,根据这个自己做相应修改,都做好了,那你就是伸手党了。

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


分享名称:杨辉三角vb.net 杨辉三角形c语言程序
网站链接:http://ybzwz.com/article/doidhhg.html