编写如下VB程序,实现上述功能。运行程序,在文本框Text1中输入随机数列“19,21,3,5,18,18,18,23,25,10,11,12,17,17,7”,单击“统计”按钮,在文本框Text2中输出5。
程序运行界面如图所示。
Dim a(1 To 100) As Integer '数组a依次存放数列中的数Dim n As Integer
Private Sub Command1_Click( )
Dim i As Integer, k As Integer, max As Integer, t As Integer Dim s As String, ch As String
s = Text1.Text n = Len(s)
i = 1: k = 1
Do While i <= n
ch = Mid(s, i, 1)
If ch <> "," Then Else k = k + 1 i = i + 1
Loop
i = 1: max = 0
Do While i <= k
t =
If t > max Then max = t i = i + t
Loop
Text2.Text = Str(max)
End Sub
Function length(p As Integer) As Integer '函数功能是计算a(p)开始的非降序段长度
Dim j As Integer, c As Integer
j = p: c = 1
Do While j <= n – 1
If Then
If a(j) < a(j + 1) Then c = c + 1 Else
Exit Do
End If
j = j + 1
Loop
length = c
End Function