vb利用随机函数产生25个10到99之间的整数,按从小到大顺序显示,谢谢,急

如题所述

你要的答案都在里面: http://wenku.baidu.com/view/8b31a66f011ca300a6c3900e.html

 

==========================================================================

 

 

 

Private Sub Form_Click() 

Dim a%(1 To 25) 

For i = 1 To 25 

a(i) = Int(Rnd * 90 + 10)

Print a(i);

Next i

Print 

For i = 1 To 24 

p = i 

For j = i + 1 To 25

If a(p) > a(j) Then p = j 

Next j 

t = a(i): a(i) = a(p): a(p) = t

Next i

Print "从小到大排序为";

For i = 1 To 25

Print a(i); 

Next i 

End Sub 

温馨提示:内容为网友见解,仅供参考
第1个回答  2012-12-04
与1、2楼不同,用了 多行文本框,程序如下:

Private Sub Command1_Click()

Dim a(1 To 25)
Dim i, j, p, t
Text1.Text = "原整数序列:" & vbCrLf
Randomize Now

For i = 1 To 25
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & a(i) & " "
Next i
Text1.Text = Text1.Text & vbCrLf & vbCrLf

‘排序

For i = 1 To 24
p = i
For j = i + 1 To 25
If a(p) > a(j) Then p = j
Next j
t = a(i): a(i) = a(p): a(p) = t
Next i

‘再次输出
Text1.Text = Text1.Text & "从小到大排序为:" & vbCrLf
For i = 1 To 25
Text1.Text = Text1.Text & a(i) & " "
Next i
End Sub
第2个回答  2012-12-04
Private Sub Command1_Click()
Dim x(1 To 25) As Integer
For i = 1 To 25
x(i) = 10 + Int(90 * Rnd())

Next
For i = 1 To 24
For j = i + 1 To 25
If x(i) > x(j) Then d = x(i): x(i) = x(j): x(j) = d
Next
Next
For i = 1 To 25
me.print x(i)
Next
End Sub
第3个回答  2012-12-04
Private Sub Command1_Click()
Dim a(24) As Integer
Call GetRandomNumber(a)
Me.Print "原顺序"
Call PrintNumber(a)
Call OrderNumber(a)
Me.Print "由小到大的顺序"
Call PrintNumber(a)
End Sub
Private Sub GetRandomNumber(ByRef r() As Integer)
Randomize
Dim i As Integer
For i = 0 To 24
r(i) = Int(90 * Rnd()) + 10
Next i
End Sub
Private Sub OrderNumber(ByRef x() As Integer)
Dim i As Integer
Dim j As Integer
Dim t As Integer
For i = 0 To 23
For j = 24 To i + 1 Step -1
If x(j) < x(j - 1) Then
t = x(j)
x(j) = x(j - 1)
x(j - 1) = t
End If
Next j
Next i
End Sub
Private Sub PrintNumber(ByRef r() As Integer)
Dim s As String
Dim i As Integer
s = ""
For i = 0 To 24
s = s & vbTab & r(i)
Next i
Me.Print s
End Sub

用vb编程实现随机产生一个100到999之间的随机数,并将此数逆序输出_百度...
语法:Rnd[(number)]如果 number 的值是 Randomize 生成小于 0 ,每次都使用 number 作为随机数种子得到的相同结果。大于 0 ,以上一个随机数为种子产生下一个随机数。等于 0 ,产生与最近生成的随机数相同的随机数。省略, 以上一个随机数为种子产生下一个随机数(同大于0)。说明:Rnd 函数返回小...

VB程序设计-利用随机函数产生80个10~99之间的随机整数
Private Sub Command1_Click()Dim A(80) As Integer, B() As Integer, Nb As Integer Dim I As Integer, J As Integer, T As Integer '随机生成80个随机数 Text1.Text = ""Randomize For I = 1 To 80 A(I) = Int(90 * Rnd) + 10 Text1.Text = Text1.Text & A(I) & " ...

...个程序,利用随机函数Rnd生成10个10-99之间的整数,并计算其中素数的...
n= [ 10+int(90*rnd) ]st = [ st + " " + n ]forj=2 to [ n ][ n1=n1+1 ][ exit for ]text1.text=[ st ]text2.text= [ n-n1 ]

关于VB随机函数的问题,急急急!!
[10,99]之间的随机数:int((99-10+1)*rnd+10) 也就是:int(90*rnd+10).这样理解:由于rnd的取值范围是[0,1) 所以当rnd为0时,结果=int(90*0+10)=int(10)=10;当rnd为0.9999时,结果 int(90*0.9999+10)=int(89.9999+10)=int(99.9999)=99 ...

请问怎样在vb生成一个1到100的随机整数?
VB生成1-100之间的随机整数,可以使用系统自带的Rnd()方法进行实现,代码如下:Private Sub Command_Click() Dim MyValue \/\/定义一个随机数 MyValue = Int((100 * Rnd) + 1) \/\/rnd()函数生成随机数 Print MyValue \/\/打印出这个随机数End SubPrivate Sub Form_Load() Randomize...

VB用随机函数产生50个【10-100】的随机整数,并按照从小到大的顺序打印...
Dim A(50) As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 50A(i) = Int(Rnd * 90 + 10)Next iPicture1.ClsPicture1.Print "排序前数据:"For i = 1 To 50Picture1.Print A(i);If i Mod 10 = 0 Then Picture1.PrintNextEnd SubPrivate Sub Command2_Click()For ...

产生随机数 vb
a(i) = Int((99 - 10 + 1) * Rnd + 10) ' 生成 10 到 99 之间的随机数值。If a(i) Mod 2 = 0 Then '如果是偶数 k = k + 1 er(k) = a(i)Else '否则是奇数 n = n + 1 ji(n) = a(i)End If Next i '以下把得到的数据显示出来 Dim s As String Print "奇数的...

利用随机函数产生80个10~99之间的随机整数,
Option Base 1 Private Function sushu(x As Integer) As Boolean Dim i As Integer For i = 2 To x - 1 If x Mod i = 0 Then Exit Function Next i sushu = True End Function Private Sub Command1_Click()Dim i As Integer, a(80) As Integer, j As Integer, b(80) As ...

利用随机函数产生20个10~99之间(包括10和99)的随机整数存入一维数组A...
i++){a[i] = rand() % 90 + 10;mean += (double) a[i]; \/\/ 在此处求和printf("第%d个数:%d\\n", i, a[i]);}mean \/= N; \/\/ 平均数printf("平均数:%lf\\n", mean);for(i = 0; i < N; ++i){if(a[i] > mean && !(a[i] & 1)) \/\/ 偶数判断 (!

VB中如何设置随机数的最大、小值 ?
在VB中,使用Rnd函数生成的随机数属于[0,1)区间的小数。若要生成某个范围内的随机整数,需利用以下公式:Int((upperbound - lowerbound + 1) * Rnd + lowerbound)。其中,upperbound表示随机数范围的上限,lowerbound则是下限。例如,若要生成位于1至10之间的随机整数,上限upperbound为10,下限lower...

相似回答