在通用部分声明三个数组
Private Sub Command1_Click()Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "系统自动生成的十个数:" & vbCrLf
For I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
Randomize
AA(I) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
End Sub
生成十个数的代码
Private Sub Command2_Click()Text2.Text = "": Text3.Text = ""
Dim AAA As Integer, BBB As Integer
For I = 1 To 9
For J = I + 1 To 10
If ZGCJ(I) < ZGCJ(J) Then
AAA = ZGCJ(I)
ZGCJ(I) = ZGCJ(J)
ZGCJ(J) = AAA
End If
If ZDCJ(J) < ZDCJ(I) Then
BBB = ZDCJ(J)
ZDCJ(J) = ZDCJ(I)
ZDCJ(I) = BBB
End If
Next J
Next I
Text2.Text = Text2.Text & "从大到小排列:" & vbCrLf
For I = 1 To 10
Text2.Text = Text2.Text & ZGCJ(I) & Space(4)
If I Mod 5 = 0 Then Text2.Text = Text2.Text & vbCrLf
Next I
Text3.Text = Text3.Text & "从小到大排列:" & vbCrLf
For I = 1 To 10
Text3.Text = Text3.Text &游仿 ZDCJ(I) & Space(4)
If I Mod 5 = 0 Then Text3.Text = Text3.Text & vbCrLf
Next I
End Sub
排序的代码。
如果需要自己输入数字,可以这样:
'如果要自己输入数字,可以修改下面的代码Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "系统自动生成的十个数:" & vbCrLf
For 明搏I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
Randomize
AA(I) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
'神槐纤----------------------------修改为:
Text1.Text = "": Text2.Text = "": Text3.Text = ""
Text1.Text = "用户输入的十个数:" & vbCrLf
For I = 1 To 10
AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0
AA(I) = Val(InputBox("请输入第" & I & "个数!"))
Text1.Text = Text1.Text & AA(I) & Space(4)
If I Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
ZGCJ(I) = AA(I)
ZDCJ(I) = AA(I)
Next I
轿握冒泡法升序排序标准代码(Vb):
for i=1 to 99
for j=i+1 to 100
if a(i)>a(j) 坦渗then
temp=a(i):a(i)=a(j):a(j)=temp
闭信庆 end if
next j
next i
程序思想是:
Option ExplicitOption Base 1
Private Function sx(ByVal n As Integer) As Boolean
Dim a() As Integer, k As Integer, i As Integer
Do
k = k + 1
ReDim Preserve a(k)
a(k) = n Mod 10
n = n \ 10
Loop Until n <= 0
陵拿 For i = 1 To UBound(a) - 1
If a(i + 1) >= a(i) Then Exit Function
尺谨搭 Next i
sx = True
End Function
Private Sub Command1_Click()
Dim a As Integer, b As Integer, i As Integer
a = Val(Text1.Text): b = Val(Text2.Text)
List1.Clear
For i = a To b
If sx(i) Then
List1.AddItem i
End If
Next i
If List1.ListCount = 0 Then List1.AddItem "无升序数"
End Sub
下面再给你一个更简单的代码:
Option ExplicitOption Base 1
Private Function sx(ByVal n As Integer) As Boolean
Dim i As Integer
For i = 2 To Len(CStr(n))
If Mid(n, i, 1) <晌铅= Mid(n, i - 1, 1) Then Exit Function
Next i
sx = True
End Function
Private Sub Command1_Click()
Dim a As Integer, b As Integer, i As Integer
a = Val(Text1.Text): b = Val(Text2.Text)
List1.Clear
For i = a To b
If sx(i) Then
List1.AddItem i
End If
Next i
If List1.ListCount = 0 Then List1.AddItem "无升序数"
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)