永发信息网

用vb来解决问题

答案:3  悬赏:80  手机版
解决时间 2021-05-03 00:40
  • 提问者网友:不爱我么
  • 2021-05-02 19:41

编程,把下面的数据输入一个二维数组中:

25 36 78 13

2 26 88 93

75 18 22 32

56 44 36 58

然后执行以下操作:

输出矩阵两个对角线上的数;

分别输出各行和各列的和

最佳答案
  • 五星知识达人网友:等灯
  • 2021-05-02 20:29
Private Sub Command1_Click()
Dim a
Dim b(1 To 4, 1 To 4) As Integer
Dim c(1 To 4) As Integer
Dim d(1 To 4) As Integer
Dim i As Integer, j As Integer
Cls
a = Array(25, 36, 78, 13, 2, 26, 88, 93, 75, 18, 22, 32, 56, 44, 36, 58)
Print "二维数组为:"
For i = 1 To 4
For j = 1 To 4
b(i, j) = a((i - 1) * 4 + j - 1)
c(i) = c(i) + b(i, j)
d(j) = d(j) + b(i, j)
Print b(i, j);
Next
Print
Next
Print "第一个对角线上的数为:"
For i = 1 To 4
For j = 1 To 4
If i = j Then Print b(i, j);
Next
Next
Print
Print "第二个对角线上的数为:"
For i = 1 To 4
For j = 1 To 4
If i + j = 5 Then Print b(i, j);
Next
Next
Print
Print "各行的和为:"
For i = 1 To 4
Print c(i);
Next
Print
Print "各列的和为:"
For i = 1 To 4
Print d(i);
Next
Print
End Sub
全部回答
  • 1楼网友:夜余生
  • 2021-05-02 22:21

dim num(4,4)

dim n,i

for n = 1 to 4

for i = 1 to 4

num(n,i)=inputbox("请输入数组的值","数值输入")'在这里开始输入你要输入的数值,即你以上的数据,按每一行输入即可

next

next

for n = 1 to 4

for i = 1 to 4

x_sum(n)=num(n,i) +x_sum(n)

if n = i then

l_sum(n)=num(n,i) +l_sum(n)

end if

next

next

for n = 1 to 4

print "第" & n & "行的数值和是" & x_sum(n)

print "第" & n & "列的数值和是" & l_sum(n)

if n = 1 or n = 4 then print "对角为" & num(n,n)

next

以上代码,如果还有什么问题的话,尽管发问

  • 2楼网友:轻熟杀无赦
  • 2021-05-02 21:43
Private Sub Form_Click() Dim juzhen(4, 4) As Integer Dim duijiaoxian1 As String Dim duijiaoxian2 As String Dim sumRow(4) As Integer Dim sumCol(4) As Integer Dim i As Integer Dim j As Integer duijiaoxian1 = "" duijiaoxian2 = "" juzhen(1, 1) = 25 juzhen(1, 2) = 36 juzhen(1, 3) = 78 juzhen(1, 4) = 13 juzhen(2, 1) = 2 juzhen(2, 2) = 26 juzhen(2, 3) = 88 juzhen(2, 4) = 93 juzhen(3, 1) = 75 juzhen(3, 2) = 18 juzhen(3, 3) = 22 juzhen(3, 4) = 32 juzhen(4, 1) = 56 juzhen(4, 2) = 44 juzhen(4, 3) = 36 juzhen(4, 4) = 58 For i = 1 To 4 duijiaoxian1 = duijiaoxian1 & juzhen(i, i) & " " duijiaoxian2 = duijiaoxian2 & juzhen(i, 5 - i) & " " Next Print "主对角线上的数为: " & duijiaoxian1 & vbCrLf Print "斜主对角线上的数为: " & duijiaoxian2 & vbCrLf For i = 1 To 4 sumRow(i) = 0 sumCol(i) = 0 For j = 1 To 4 sumRow(i) = sumRow(i) + juzhen(i, j) sumCol(i) = sumCol(i) + juzhen(j, i) Next Print "第" & CStr(i) & "行的和为"; sumRow(i) & vbCrLf Print "第" & CStr(i) & "列的和为"; sumCol(i) & vbCrLf Next End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯