用VB编写程序,把下面的数据输入到一个二维数组中:
编写程序,把下面的数据输入到一个二维数组中:153070111425901007782130554031521然后执行以下操作:1)输出矩阵两个对角线上的数;2)分别输出...
编写程序,把下面的数据输入到一个二维数组中:
15 30 70 11
14 25 90 100
77 8 21 30
55 40 31 52
1然后执行以下操作:
1) 输出矩阵两个对角线上的数;
2) 分别输出各行和各列的和。
3) 交换第一行和第三行的位置。
4) 交换第二行和第四行的位置。
5) 输出处理后的数组。 展开
15 30 70 11
14 25 90 100
77 8 21 30
55 40 31 52
1然后执行以下操作:
1) 输出矩阵两个对角线上的数;
2) 分别输出各行和各列的和。
3) 交换第一行和第三行的位置。
4) 交换第二行和第四行的位置。
5) 输出处理后的数组。 展开
3个回答
展开全部
Dim a(4, 4), b(4, 4) As Integer
For i = 0 To 3
For j = 0 To 3
a(i, j) = Val(InputBox("请输入第" & i + 1 & "行第" & j + 1 & "列的数"))
Next j
Next i
Print "原始数据"
For i = 0 To 3
Print a(i, 0) & " " & a(i, 1) & " " & a(i, 2) & " " & a(i, 3) & "和" & Val(a(i, 0) + a(i, 1) + a(i, 2) + a(i, 3))
Next i
Print " 和 和 和 和"
For j = 0 To 3
Print " "; Val(a(0, j) + a(1, j) + a(2, j) + a(3, j));
Next j
Print
'对角线
For i = 0 To 3
Print Tab(i * 2); a(i, i)
Next i
Print
For i = 0 To 3
Print Tab((3 - i) * 2); a(i, 3 - i)
Next i
Print
'调整
For j = 0 To 3
b(2, j) = a(0, j) '第一行和第三行
b(0, j) = a(2, j)
b(1, j) = a(3, j)
b(3, j) = a(1, j)
Next j
Print "调整后数据"
For i = 0 To 3
Print b(i, 0) & " " & b(i, 1) & " " & b(i, 2) & " " & b(i, 3)
Next i
For i = 0 To 3
For j = 0 To 3
a(i, j) = Val(InputBox("请输入第" & i + 1 & "行第" & j + 1 & "列的数"))
Next j
Next i
Print "原始数据"
For i = 0 To 3
Print a(i, 0) & " " & a(i, 1) & " " & a(i, 2) & " " & a(i, 3) & "和" & Val(a(i, 0) + a(i, 1) + a(i, 2) + a(i, 3))
Next i
Print " 和 和 和 和"
For j = 0 To 3
Print " "; Val(a(0, j) + a(1, j) + a(2, j) + a(3, j));
Next j
'对角线
For i = 0 To 3
Print Tab(i * 2); a(i, i)
Next i
For i = 0 To 3
Print Tab((3 - i) * 2); a(i, 3 - i)
Next i
'调整
For j = 0 To 3
b(2, j) = a(0, j) '第一行和第三行
b(0, j) = a(2, j)
b(1, j) = a(3, j)
b(3, j) = a(1, j)
Next j
Print "调整后数据"
For i = 0 To 3
Print b(i, 0) & " " & b(i, 1) & " " & b(i, 2) & " " & b(i, 3)
Next i
展开全部
dim i as Integer, j as Integer, sum as Integer
dim shuzu
shuzu = Array(
(15, 30, 70, 11),
(14, 25, 90, 100),
(77, 8, 21, 30),
(55, 40, 31, 52)
)
' 矩阵对角线上的数字特点是:
' 1)横向坐标和纵向坐标数值相同,例如[0][0]、[1][1]……
' 2)横坐标+纵坐标=5
print "第一组对角线坐标为:" & chr(13)
for i = 1 t0 4
print shuzu(i)(i)
next i
print chr(13) & "第二组对角线坐标:" & chr(13)
for i = 1 to 4
print shuzu(i)(5-i)
next i
' 第i行之和 = shuzu(i)(1) + ... + shuzu(i)(4)
' 第i列之和 = shuzu(1)(i) + ... + shuzu(4)(i)
for i = 1 to 4
sum = 0
for j = 1 to 4
sum = sum + shuzu(i)(j)
next j
print "第" & i & "行数字之和:" & sum & chr(13)
sum = 0
for j = 1 to 4
sum = sum + shuzu(j)(i)
next j
print chr(13) & "第" & i & "列数字之和:" & sum & chr(13)
next i
' 交换1行和3行,同时交换2行和4行,期中使用j做中转变量
for i = 1 to 4
j = shuzu(1)(i)
shuzu(1)(i) = shuzu(3)(i)
shuzu(3)(i) = j
j = shuzu(2)(i)
shuzu(2)(i) = shuzu(4)(i)
shuzu(4)(i) = j
next i
' 输出矩阵
print "经过交换后矩阵为:" & chr(13)
for i = 1 to 4
for j = 1 to 4
print shuzu(i)(j) & " "
next j
print chr(13)
next i
dim shuzu
shuzu = Array(
(15, 30, 70, 11),
(14, 25, 90, 100),
(77, 8, 21, 30),
(55, 40, 31, 52)
)
' 矩阵对角线上的数字特点是:
' 1)横向坐标和纵向坐标数值相同,例如[0][0]、[1][1]……
' 2)横坐标+纵坐标=5
print "第一组对角线坐标为:" & chr(13)
for i = 1 t0 4
print shuzu(i)(i)
next i
print chr(13) & "第二组对角线坐标:" & chr(13)
for i = 1 to 4
print shuzu(i)(5-i)
next i
' 第i行之和 = shuzu(i)(1) + ... + shuzu(i)(4)
' 第i列之和 = shuzu(1)(i) + ... + shuzu(4)(i)
for i = 1 to 4
sum = 0
for j = 1 to 4
sum = sum + shuzu(i)(j)
next j
print "第" & i & "行数字之和:" & sum & chr(13)
sum = 0
for j = 1 to 4
sum = sum + shuzu(j)(i)
next j
print chr(13) & "第" & i & "列数字之和:" & sum & chr(13)
next i
' 交换1行和3行,同时交换2行和4行,期中使用j做中转变量
for i = 1 to 4
j = shuzu(1)(i)
shuzu(1)(i) = shuzu(3)(i)
shuzu(3)(i) = j
j = shuzu(2)(i)
shuzu(2)(i) = shuzu(4)(i)
shuzu(4)(i) = j
next i
' 输出矩阵
print "经过交换后矩阵为:" & chr(13)
for i = 1 to 4
for j = 1 to 4
print shuzu(i)(j) & " "
next j
print chr(13)
next i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Option Base 1
Private Sub Form_Click()
Dim a() As Integer
Dim b() As Integer
Dim c() As Integer
Dim d() As Integer
Dim e() As Integer
Dim m, n, i, j, summ, sumn
m = 4: n = 4
ReDim a(5, 5)
For i = 1 To m
For j = 1 To n
a(i, j) = InputBox("请输入")
Print a(i, j),
Next j
Print
Next i
Print
'(1)输出矩阵2个对角线上的数
ReDim b(5, 5)
For i = 1 To m
For j = 1 To n
If i = j Then
b(i, j) = a(i, j)
Print b(i, j);
End If
Next j
Next i
Print
ReDim c(5, 5)
For i = 1 To m
For j = 1 To n
If i = j Then
c(i, j) = a(5 - i, i)
Print c(i, j);
End If
Next j
Next i
Print
'(2)分别输出各行和各列的和
For i = 1 To m
summ = 0: sumn = 0
For j = 1 To n
summ = summ + a(i, j)
sumn = sumn + a(j, i)
Next j
Print "行的和:" & summ, "列的和:" & sumn
Next i
'(3)交换第一行和第三行的位置
ReDim d(5, 5)
i = 1
For j = 1 To n
c(i, j) = a(3, j)
a(3, j) = a(i, j)
a(i, j) = c(i, j)
Next j
'(4)交换第二行和第四行的位置
ReDim e(5, 5)
i = 1
For j = 1 To n
e(i, j) = a(4, j)
a(4, j) = a(2, j)
a(2, j) = e(i, j)
Next j
'(5)输出处理后的数据
Print
For i = 1 To m
For j = 1 To n
Print a(i, j);
Next j
Print
Next i
End Sub
这是我写的,希望能帮到你
Option Base 1
Private Sub Form_Click()
Dim a() As Integer
Dim b() As Integer
Dim c() As Integer
Dim d() As Integer
Dim e() As Integer
Dim m, n, i, j, summ, sumn
m = 4: n = 4
ReDim a(5, 5)
For i = 1 To m
For j = 1 To n
a(i, j) = InputBox("请输入")
Print a(i, j),
Next j
Next i
'(1)输出矩阵2个对角线上的数
ReDim b(5, 5)
For i = 1 To m
For j = 1 To n
If i = j Then
b(i, j) = a(i, j)
Print b(i, j);
End If
Next j
Next i
ReDim c(5, 5)
For i = 1 To m
For j = 1 To n
If i = j Then
c(i, j) = a(5 - i, i)
Print c(i, j);
End If
Next j
Next i
'(2)分别输出各行和各列的和
For i = 1 To m
summ = 0: sumn = 0
For j = 1 To n
summ = summ + a(i, j)
sumn = sumn + a(j, i)
Next j
Print "行的和:" & summ, "列的和:" & sumn
Next i
'(3)交换第一行和第三行的位置
ReDim d(5, 5)
i = 1
For j = 1 To n
c(i, j) = a(3, j)
a(3, j) = a(i, j)
a(i, j) = c(i, j)
Next j
'(4)交换第二行和第四行的位置
ReDim e(5, 5)
i = 1
For j = 1 To n
e(i, j) = a(4, j)
a(4, j) = a(2, j)
a(2, j) = e(i, j)
Next j
'(5)输出处理后的数据
For i = 1 To m
For j = 1 To n
Print a(i, j);
Next j
Next i
End Sub
这是我写的,希望能帮到你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询