> 其他 >
vb 关于数组的问题1.利用随机函数生成一个4*5的矩阵(二维数组),范围是[1,100]之间的整数,求所有元
素的最大值
人气:341 ℃ 时间:2020-08-30 18:54:31
解答
Dim a%(4,5)Private Sub Command1_Click() '产生并输出For i = 1 To 4For j = 1 To 5a(i,j) = Int(Rnd * 100) '[1,100]Print a(i,j);Next jPrint '换行Next iEnd SubPrivate Sub Command2_Click() '求最小值Max = a(...如果同时显示最大值的坐标怎么办,Dim a%(4, 5)Dim imax As IntegerDim jmax As Integer Private Sub Command1_Click() '产生并输出For i = 1 To 4For J = 1 To 5a(i, J) = Int(Rnd * 100) '[1,100]Print a(i, J);Next JPrint '换行Next iEnd SubPrivate Sub Command2_Click() '求最小值Max = a(1, 1) '最大值的初始值为第一个元素For i = 1 To 4For J = 1 To 5If Max < a(i, J) ThenMax = a(i, J)imax = ijmax = J End IfNext JNext iPrint "最大值为:"; Max; ",坐标为(" & imax & "," & jmax & ")"End Sub 坐标加上了
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版