vb编程定义数组a【100】,以数组为参数,编写并调用一下函数
(1)定义函数input,为数组的所有元素赋给随机数(vb为sub)(2)定义函数ouput,输出数组的所有元素(vb为sub)(3)定义函数sort,将数组从小到大排序...
(1) 定义函数input,为数组的所有元素赋给随机数(vb为sub)(2) 定义函数ouput,输出数组的所有元素(vb为sub)(3) 定义函数sort,将数组从小到大排序(4) 定义函数average,求数组的平均值(5) 定义函数max 求数组的最大值(6) 定义函数sum,求数组的和
展开
1个回答
展开全部
Dim a(9, 9) As Integer
Private Sub Command1_Click()
Cls
'输入
For i = 0 To 9
For j = 0 To 9
Randomize
a(i, j) = Int(101 * Rnd)
Next j
Next i
'输出
For i = 0 To 9
For j = 0 To 9
Print Format(a(i, j), "00") & " ";
Next j
Print
Next i
End Sub
Private Sub Command2_Click()
m = 0
n = 10000000
s1 = ""
s2 = ""
For i = 0 To 9
For j = 0 To 9
If a(i, j) > m Then
m = a(i, j)
s1 = "a(" & i & "," & j & ")"
End If
If a(i, j) < n Then
n = a(i, j)
s2 = "a(" & i & "," & j & ")"
End If
Next j
Next i
Print
Print "最大元素 是:"; s1; "最小元素 是:"; s2
Print
Print "最大元素值 是:"; m; "最小元素值 是:"; n
End Sub
Private Sub Command3_Click()
s = 0
For i = 0 To 9
For j = 0 To 9
If i = j Then
s = s + a(i, j)
End If
Next j
Next i
Print
Print "主对角线元素之和 是:"; s
End Sub
Private Sub Command4_Click()
s = 0
For i = 0 To 9
For j = 0 To 9
If i > j Then
s = s + a(i, j)
End If
Next j
Next i
Print
Print "行号>列号元素之和 是:"; s
End Sub
Private Sub Command1_Click()
Cls
'输入
For i = 0 To 9
For j = 0 To 9
Randomize
a(i, j) = Int(101 * Rnd)
Next j
Next i
'输出
For i = 0 To 9
For j = 0 To 9
Print Format(a(i, j), "00") & " ";
Next j
Next i
End Sub
Private Sub Command2_Click()
m = 0
n = 10000000
s1 = ""
s2 = ""
For i = 0 To 9
For j = 0 To 9
If a(i, j) > m Then
m = a(i, j)
s1 = "a(" & i & "," & j & ")"
End If
If a(i, j) < n Then
n = a(i, j)
s2 = "a(" & i & "," & j & ")"
End If
Next j
Next i
Print "最大元素 是:"; s1; "最小元素 是:"; s2
Print "最大元素值 是:"; m; "最小元素值 是:"; n
End Sub
Private Sub Command3_Click()
s = 0
For i = 0 To 9
For j = 0 To 9
If i = j Then
s = s + a(i, j)
End If
Next j
Next i
Print "主对角线元素之和 是:"; s
End Sub
Private Sub Command4_Click()
s = 0
For i = 0 To 9
For j = 0 To 9
If i > j Then
s = s + a(i, j)
End If
Next j
Next i
Print "行号>列号元素之和 是:"; s
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询