vb编程,随机数和排序的问题,
程序打开后在list1中显示30个100到3000的随机数,点击筛选,选出是闰年的年份显示在list2中,在点击排序,将list2中的数字按从小到大排序显示在list2中...
程序打开后在list1中显示30个100到3000的随机数,点击筛选,选出是闰年的年份显示在list2中,在点击排序,将list2中的数字按从小到大排序显示在list2 中。代码应该如何编写?
界面如下: 展开
界面如下: 展开
4个回答
2014-12-04
展开全部
代码就按你的要求写就行了啊,
程序打开后在list1中显示30个100到3000的随机数,点击筛选,选出是闰年的年份显示在list2中,
你先从第一个到最后一个判断一下,如果是闰年的年份,添加到LIST2中,如果不是就不管了。
在点击排序,将list2中的数字按从小到大排序显示在list2 中。代码应该如何编写?
先建一个数组,把LIST2的数字放到数组中,然后用冒泡法排序,最后清除LIST2,按数组排序的写回去。
程序打开后在list1中显示30个100到3000的随机数,点击筛选,选出是闰年的年份显示在list2中,
你先从第一个到最后一个判断一下,如果是闰年的年份,添加到LIST2中,如果不是就不管了。
在点击排序,将list2中的数字按从小到大排序显示在list2 中。代码应该如何编写?
先建一个数组,把LIST2的数字放到数组中,然后用冒泡法排序,最后清除LIST2,按数组排序的写回去。
展开全部
Private Sub Command1_Click() '筛选
Dim i As Integer, n As Integer
For i = 0 To List1.ListCount - 1
n = Val(List1.List(i))
If (n Mod 4 = 0 And n Mod 100 <> 0) Or n Mod 400 = 0 Then
List2.AddItem n
End If
Next
End Sub
Private Sub Command2_Click() '排序
Dim i As Integer, j As Integer
Dim tmp As Integer
For i = 0 To List2.ListCount - 2
For j = i To List2.ListCount - 1
If Val(List2.List(i)) > Val(List2.List(j)) Then
tmp = List2.List(j)
List2.List(j) = List2.List(i)
List2.List(i) = tmp
End If
Next
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 1 To 30
List1.AddItem Int(Rnd * 2900) + 100
Next
End Sub
Dim i As Integer, n As Integer
For i = 0 To List1.ListCount - 1
n = Val(List1.List(i))
If (n Mod 4 = 0 And n Mod 100 <> 0) Or n Mod 400 = 0 Then
List2.AddItem n
End If
Next
End Sub
Private Sub Command2_Click() '排序
Dim i As Integer, j As Integer
Dim tmp As Integer
For i = 0 To List2.ListCount - 2
For j = i To List2.ListCount - 1
If Val(List2.List(i)) > Val(List2.List(j)) Then
tmp = List2.List(j)
List2.List(j) = List2.List(i)
List2.List(i) = tmp
End If
Next
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 1 To 30
List1.AddItem Int(Rnd * 2900) + 100
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
List2.Clear
For i = 0 To 29
x = List1.List(i)
If x Mod 4 = 0 And x Mod 100 > 0 Or x Mod 400 = 0 Then List2.AddItem x
Next i
End Sub
Private Sub Command2_Click()
Dim a(30) As Integer
n = List2.ListCount
For i = 0 To n - 1
a(i) = List2.List(i)
Next i
For i = 0 To n - 2
For j = 0 To n - 2 - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
List2.AddItem a(i)
Next i
List2.Clear
For i = 0 To n - 1
List2.AddItem a(i)
Next i
End Sub
Private Sub Form_Load()
List1.Clear
Randomize
For i = 1 To 30
a = Int(2901 * Rnd) + 100
List1.AddItem a
Next i
End Sub
List2.Clear
For i = 0 To 29
x = List1.List(i)
If x Mod 4 = 0 And x Mod 100 > 0 Or x Mod 400 = 0 Then List2.AddItem x
Next i
End Sub
Private Sub Command2_Click()
Dim a(30) As Integer
n = List2.ListCount
For i = 0 To n - 1
a(i) = List2.List(i)
Next i
For i = 0 To n - 2
For j = 0 To n - 2 - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
List2.AddItem a(i)
Next i
List2.Clear
For i = 0 To n - 1
List2.AddItem a(i)
Next i
End Sub
Private Sub Form_Load()
List1.Clear
Randomize
For i = 1 To 30
a = Int(2901 * Rnd) + 100
List1.AddItem a
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用于WINDOWS应用程序开发的BASIC除Visual BASIC,经常应用的还有两种编程应用软件工具:CA-Realizer和GFA-BASIC。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询