来做道题

来源:百度知道 编辑:UC知道 时间:2024/06/19 09:35:02
下面程序的功能是从键盘上输入不多于100个的正整数,存放于数组a中。当输入0或负数时,结束输入,计算出这些数的平均值m。如果a中元素小于m,则存放在数组a的左端;否则就存放在数组s的右端,如图所示。最后,输出全部数组元素。
2 1 3 3 … 5 4 4 6

程序的思想是:分别设置数组的左端和右端指针,比较数组a中元素与m的大小,决定存放于数组s的左端或右端,调整相应指针位置。
Private Sub Command1_Click()
Dim a%(1 To 100), pLeft%, pRight%, i%, t%, n%, m!
n = 0: m = 0
t = InputBox("input data:")
Do While___(1)___ And n < 100 ' 判断结束输入标志
n = n + 1
a(n) = t
_____(2)_____
t = InputBox("input data:")
Loop
m = m / n
pLeft = 1 ' 设置数组的左端指针
pRight = n ' 设置数组的右端指针
Do While pLeft < pRight
If a(pLeft) < m Then ' 小于m
________(3)_______
Else ' 大于m
________(4)_______
pRight = pRight - 1
End If
Loop
For i = 1 To n
Print " "; a(i);
Next i
End Sub

编程就编程了 答什么

这样改,不知对不对

Private Sub Command1_Click()
Dim a%(1 To 100), pLeft%, pRight%, i%, t%, n%, m!
n = 0: m = 0
t = InputBox("input data:")
Do While t <> 0 And n < 100 ' 判断结束输入标志
n = n + 1
a(n) = t
m = m + t
t = InputBox("input data:")
Loop
m = m / n
pLeft = 1 ' 设置数组的左端指针
pRight = n ' 设置数组的右端指针
Do While pLeft < pRight
If a(pLeft) < m Then ' 小于m
pLeft = pLeft + 1
Else ' 大于m
t = a(pLeft): a(pLeft) = a(pRight): a(pRight) = t
pRight = pRight - 1
End If
Loop
For i = 1 To n
Print " "; a(i);
Next i
End Sub

1.t>0
2.m=m+a(n)
3.pleft=pleft+1
4.t=a(pleft):a(pleft)=a(pright):a(pright)=t:pright=pright-1