VB编程 随机产生n个10-100的整数,求其中的最大值,最小值,总和及平均值 20
①定义一个Sub子过程Mmsa,该过程的功能是计算并返回一维数组的最大值,最小值,总和及平均值。其开始语句定义为SubMmsa(a()AsInteger,max%,min...
①定义一个Sub子过程Mmsa,该过程的功能是计算并返回一维数组的最大值,最小值,总和及平均值。其开始语句定义为 Sub Mmsa(a()As Integer ,max%,min%,sum%,ave%)
②在窗体的单击事件中,随机产生n个10-100的整数(n从键盘输入),并调用Mmsa过程完成要求 展开
②在窗体的单击事件中,随机产生n个10-100的整数(n从键盘输入),并调用Mmsa过程完成要求 展开
2个回答
展开全部
Private Sub Command1_Click()
Randomize
Dim a(10) As Integer, imas as integer, imin as integer, Average as integer
imax = 49
imin = 101
Average=0
For i = 0 To 9
a(i) = Int(Rnd * 51) + 50
Average=Average+a(i)
If imax < a(i) Then imax = a(i)
If imin > a(i) Then imin = a(i)
Print a(i),
Next
Print "最大值和最小值和平均值是:"; imax; imin; Average / 10
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public n As Integer
Private Sub Form_Click()
dim a()As Integer,max%,min%,sum%,ave%,i
n = Cint(InputBox("请输入随机产生几个数?"))
Randomize
For i=0 TO n-1
a(i) = Int(Rnd * (10 - 100 + 1) + 100)
Next i
Mmsa a(i)
End Sub
Sub Mmsa(a()As Integer)
dim i,j,k,t,max%,min%,sum%,ave%
For i = 0 To n - 2
For j = i + 1 To n-1
If a(j) < a(i) Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
max%=a(n-1)
min%=a(0)
For k= 0 To n -1
sum%=sum%+a(k)
Next k
ave%=sum%/n
print max%
print min%
print sum%
print ave%
End Sub
Private Sub Form_Click()
dim a()As Integer,max%,min%,sum%,ave%,i
n = Cint(InputBox("请输入随机产生几个数?"))
Randomize
For i=0 TO n-1
a(i) = Int(Rnd * (10 - 100 + 1) + 100)
Next i
Mmsa a(i)
End Sub
Sub Mmsa(a()As Integer)
dim i,j,k,t,max%,min%,sum%,ave%
For i = 0 To n - 2
For j = i + 1 To n-1
If a(j) < a(i) Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
max%=a(n-1)
min%=a(0)
For k= 0 To n -1
sum%=sum%+a(k)
Next k
ave%=sum%/n
print max%
print min%
print sum%
print ave%
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询