算法分析:要使得到的5位数字最小,首先需保证能取到5个数字,且首位应尽量小,那么取首位数的范围应保证余下有4个数字,即在前4位中选最小非0的数字。
程序运行时,在文本框Text1中输入一个数字字符串,在文本框Text2中输入要移除的数字个数,单击“运行”按钮CmdRun后,在标签Labell显示得到的最小新数,程序运行界面如图b所示。
Private Sub CmdRun_ Click()
Dim Num As String,New_num As String ' Num为输入的数字字符串
Dim i As Integer, j As Integer, m As Integer,
Dim As Integer, s As Integer, k As Integer
Dim a(30) As String, b(30) As Integer
Num = Text1. Text: s = Len(Num)
k = Val (Text2. Text) 'k为删除数字个数
For i=1 To s
a(i) = Mid(Num,i,1)
Nexti
j =1
m=1
n=
For i=m+l To n '取第一个非零最小数字
If Then m=I '加框处程序代码有误,请改正
Next i
b(j)= m
Do While '取其他最小数字
m=m+1
n=n+1
For i=m+1 To n
If a(i) < a(m) Then m= i
Next i
j =j+1:b(j)=m
Loop
For i= m+1 To s '最后直接取的数字
j =j+1:b(j)=i
Next i
For j=1 To s- k '输出最小数
New_ num =
Next j
Labell. Caption = New_num
End Sub