编一程序,把一个m行n列矩阵中的元素存放到一个二维数组中,并求出该数组的平均值,最大值和最小值

2024-11-28 23:57:34
推荐回答(1个)
回答1:

dim m as integer,n as integer

dim aven as double,max as double,min as double
dim a() as double
private sub command1_click()
m=val(inputbox("请输入矩阵的行数:"))
n=val(inputbox("请输入矩阵的列数"))
redim a(1 to m,1 to n)
'把矩阵中的元素存放到二维数组中
for i=1 to m
for j=1 to n
a(i,j)=val(inputbox("请输入矩阵的元素:"))
print a(i,j); '输出数组的元素
next j
print
next i
'求数组的平均值
for i =1 to m
for j=1 to n
sum=sum+ a(i,j)
next j
next i
aven=sum/(m*n)
print "数组的平均值为:" & aven

'求数组的最大值
max=a(1,1)
for i= 1 to m
for j= 1 to n
if max next j
next i
print "数组的最大值为:" & max
'求数组的最小值
min=a(1,1)
for i= 1 to m
for j=1 to n
if min>a(i,j) then min=a(i,j)
next j
next i
print "数组的最小值为:" & min
end sub