急问啊!!!这道VB编程题怎么做啊??? 20
编写程序,把下面的数据输入一个二维数组中:25367813122688937518223256443658然后执行以下操作:(1)输出矩阵两个对角线上的数;(2)分别输出...
编写程序,把下面的数据输入一个二维数组中:
25 36 78 13
12 26 88 93
75 18 22 32
56 44 36 58
然后执行以下操作:
(1)输出矩阵两个对角线上的数;
(2)分别输出各行和各列的和;
(3)交换第一行和第三行的位置;
(4)交换第二行和第四行的位置;
(5)输出处理后的数组。 展开
25 36 78 13
12 26 88 93
75 18 22 32
56 44 36 58
然后执行以下操作:
(1)输出矩阵两个对角线上的数;
(2)分别输出各行和各列的和;
(3)交换第一行和第三行的位置;
(4)交换第二行和第四行的位置;
(5)输出处理后的数组。 展开
1个回答
展开全部
Private Sub Command1_Click()
Dim a(3, 3) As Integer, i%, j%, SumA%, SumB%, t%, LSum(3) As Integer, CSum(3) As Integer
a(0, 0) = 25
a(0, 1) = 36
a(0, 2) = 78
a(0, 3) = 13
a(1, 0) = 12
a(1, 1) = 26
a(1, 2) = 88
a(1, 3) = 93
a(2, 0) = 75
a(2, 1) = 18
a(2, 2) = 22
a(2, 3) = 32
a(3, 0) = 56
a(3, 1) = 44
a(3, 2) = 36
a(3, 3) = 58
SumA = 0
SumB = 0
Print "原数组为:"
For i = 0 To 3
For j = 0 To 3
Print a(i, j),
Next j
Print
Next i
For i = 0 To 3
SumA = SumA + a(i, i)
SumB = SumB + a(i, 3 - i)
Next i
Print "主对角线和为:", SumA
Print "副对角线和为:", SumB
For i = 0 To 3
For j = 0 To 3
LSum(i) = LSum(i) + a(i, j)
CSum(i) = CSum(i) + a(j, i)
Next j
Next i
For i = 0 To 3
Print "第" & i + 1 & "行的和为:", LSum(i)
Next i
For i = 0 To 3
Print "第" & i + 1 & "列的和为:", CSum(i)
Next i
For i = 0 To 3
t = a(0, i)
a(0, i) = a(2, i)
a(2, i) = t
t = a(1, i)
a(1, i) = a(3, i)
a(3, i) = t
Next i
Print "调换后的数组为:"
For i = 0 To 3
For j = 0 To 3
Print a(i, j),
Next j
Print
Next i
End Sub
Dim a(3, 3) As Integer, i%, j%, SumA%, SumB%, t%, LSum(3) As Integer, CSum(3) As Integer
a(0, 0) = 25
a(0, 1) = 36
a(0, 2) = 78
a(0, 3) = 13
a(1, 0) = 12
a(1, 1) = 26
a(1, 2) = 88
a(1, 3) = 93
a(2, 0) = 75
a(2, 1) = 18
a(2, 2) = 22
a(2, 3) = 32
a(3, 0) = 56
a(3, 1) = 44
a(3, 2) = 36
a(3, 3) = 58
SumA = 0
SumB = 0
Print "原数组为:"
For i = 0 To 3
For j = 0 To 3
Print a(i, j),
Next j
Next i
For i = 0 To 3
SumA = SumA + a(i, i)
SumB = SumB + a(i, 3 - i)
Next i
Print "主对角线和为:", SumA
Print "副对角线和为:", SumB
For i = 0 To 3
For j = 0 To 3
LSum(i) = LSum(i) + a(i, j)
CSum(i) = CSum(i) + a(j, i)
Next j
Next i
For i = 0 To 3
Print "第" & i + 1 & "行的和为:", LSum(i)
Next i
For i = 0 To 3
Print "第" & i + 1 & "列的和为:", CSum(i)
Next i
For i = 0 To 3
t = a(0, i)
a(0, i) = a(2, i)
a(2, i) = t
t = a(1, i)
a(1, i) = a(3, i)
a(3, i) = t
Next i
Print "调换后的数组为:"
For i = 0 To 3
For j = 0 To 3
Print a(i, j),
Next j
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询