3 static declare an d array, the input and output the array values of each element (20) requirements: 1 are calculated and the output array and the principal diagonal and the secondary diagonal elements,
2. The exchange of the entire value of the array output after 1, 3 lines
3. The exchange of the row and column of the array output after the entire value of the array (line variables in columns I use
CodePudding user response:
Should be written in VBS, vb6 can also be used:
Dim arr (2, 2)
For I=lbound (arr, 1) To ubound (arr, 1)
For j=lbound (arr, 2) To ubound (arr, 2)
Arr (I, j)=inputbox (" please input array (" & amp; I & amp; ", "& amp; J & amp; ") value: ")
Next
Next
S="input array:" & amp; VBCRLF
Msgbox printarray (arr, s)
S="principal diagonal and:"
Sum=0
For I=lbound (arr, 1) To ubound (arr, 1)
Sum=sum + CInt (arr (I, I))
Next
Msgbox s & amp; The sum
S="secondary diagonal and:"
Sum=0
For I=lbound (arr, 1) To ubound (arr, 1)
Sum=sum + CInt (arr (ubound (arr, 1) - I, I))
Next
Msgbox s & amp; The sum
S="exchange: 1, 3 line array" & amp; VBCRLF
M=0
N=2
For I=lbound (arr, 2) To ubound (arr, 2)
Temp=arr (m, I)
Arr (m, I)=arr (n, I)
Arr (n, I)=temp
Next
Msgbox printarray (arr, s)
S="exchange after the row and column array:" & amp; VBCRLF
For I=lbound (arr, 1) To ubound (arr, 1)
For j=I To ubound (arr, 2)
Temp=arr (I, j)
Arr (I, j)=arr (j, I)
Arr (j, I)=temp
Next
Next
Msgbox printarray (arr, s)
The Function PrintArray (ByVal arr (), ByVal s)
For I=lbound (arr, 1) To ubound (arr, 1)
For j=lbound (arr, 2) To ubound (arr, 2)
S=s & amp; Arr (I, j)
If j & lt; Ubound (arr, 2) Then
S=s & amp; ", "
End the If
Next
If I & lt; Ubound (arr. 1) Then
S=s & amp; VBCRLF
End the If
Next
PrintArray=s
End the Function
Run the example:
Download address:
Link: https://pan.baidu.com/s/1xBire-oVnploWI1xlm5H2w
The extracted code: 01 p2