vb.net随机排序 vb随机数排序
编写一个 VB.NET 程序,产生 100 个 100 以内的随机数,将他们从大到小排序后输出
Private Sub Command1_Click()
公司主营业务:成都网站建设、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出海城免费做网站回馈大家。
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100 '给数组a一百个元素赋值,并换每行十个数字输出来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
For i = 100 To 2 Step -1 '用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j) a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100 '输出排好序的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
vb.net的随机3个数字,然后排序一下
给你一个最简单的冒泡排序代码:
将三个数放到一个数组中。
a(0)=val(text1.text):a(1)=val(text2.text):a(2)=val(text3.text)
dim flag as Boolean,temp as Integer
for i = 0 to 2
flag = true
for j = 2 to 1
if a(j)a(j-1) then
temp = a(j-1)
a(j-1) = a(j)
a(j) = temp
flag = false
end if
next j
if flag then Exit For
next i
text4.text=a(0):text5.text=a(1):text6.text=a(2)
VB.NET 程序 随机产生10个整数并进行排序
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim N As Integer = 9
Randomize()
Dim xx(9) As Integer
For i As Integer = 0 To N
xx(i) = Int(Rnd() * 1000) '产生 [0,1000) 之间的整数
Next
For i As Integer = 0 To N - 1
For j As Integer = i + 1 To N
If xx(i) xx(j) Then
Dim temp As Integer = 0
temp = xx(i) : xx(i) = xx(j) : xx(j) = temp
End If
Next
Next
Dim sum As Integer = 0
For i As Integer = 0 To N
TextBox1.Text += xx(i) vbCrLf
sum += xx(i)
Next
TextBox1.Text += "最大值:" xx(9) vbCrLf "最小值:" xx(0) vbCrLf "平均值:" sum / 10
End Sub
End Class
用VB.NET随机产生0~100之间的10个整数 完成从小到大的排列、、、、、、、、、、、、急求急求呀 要考试了、
'vb.net2008
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a(9), b(9) As Integer
Randomize()
For i = 0 To 9
a(i) = Int(Rnd() * (101))
Next
System.Array.Copy(a, b, 10) '复制数组
System.Array.Sort(b) '排序,数组b就是小到大的排列
End Sub
End Class
求vb.net(vb2010)程序代码 产生30个50以内的随机正整数,将他们从大到小排序后输出
vb2010写的:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim str As String = ""
Dim a(30) As Integer
Dim temp As Integer
str = str "生成的30个随机数字是 " vbCrLf
For i = 1 To 30
a(i) = Int(Rnd() * 50 + 1)
str = str a(i) " "
If i Mod 10 = 0 Then
str = str vbCrLf
End If
Next
str = str vbCrLf
For i = 1 To 30
For j = 1 To 30 - i
If a(j) a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
str = str "排序后的数字是 " vbCrLf
For i = 1 To 30
str = str a(i) " "
If i Mod 10 = 0 Then
str = str vbCrLf
End If
Next
TextBox6.Text = str
End Sub
运行结果:
生成的30个随机数字是
36 27 29 15 16 39 1 39 41 36
3 21 44 40 19 49 44 3 48 19
27 39 3 30 24 15 32 33 14 14
排序后的数字是
49 48 44 44 41 40 39 39 39 36
36 33 32 30 29 27 27 24 21 19
19 16 15 15 14 14 3 3 3 1
网站栏目:vb.net随机排序 vb随机数排序
当前网址:http://myzitong.com/article/hiopej.html