vb编写:建立并输出一个n*n的矩阵,该矩阵的主次对角线元素是1,其余元素均为0
1个回答
展开全部
n = 40 ‘矩阵大小
Dim x() As Long
ReDim x(n, n)
For a = 1 To n
x(a, a) = 1
x(a, n - (a - 1)) = 1
Next
For a = 1 To n
For b = 1 To n
Print x(a, b);
Next
Print "" Next
好了测试无错!
Dim x() As Long
ReDim x(n, n)
For a = 1 To n
x(a, a) = 1
x(a, n - (a - 1)) = 1
Next
For a = 1 To n
For b = 1 To n
Print x(a, b);
Next
Print "" Next
好了测试无错!
追问
你确定?为什么我把它复制粘贴进去运行不了啊?
追答
Private Sub Form_Load()
Me.AutoRedraw = True
n = 20 '矩阵大小
Dim x() As Long
ReDim x(n, n)
For a = 1 To n
x(a, a) = 1
x(a, n - (a - 1)) = 1
Next
For a = 1 To n
For b = 1 To n
Print x(a, b);
Next
Print ""
Next
End Sub
再试试看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询