标题:[求助]编写程序,随机产生20整数到文本框中,将其中的奇数按从小到大的顺序 ...
只看楼主
wangshuang19
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-12-17
 问题点数:0 回复次数:9 
[求助]编写程序,随机产生20整数到文本框中,将其中的奇数按从小到大的顺序在一文本

编写程序,随机产生20整数到文本框中,将其中的奇数按从小到大的顺序在一文本框中输出.

搜索更多相关主题的帖子: 文本框 整数 奇数 顺序 从小到大 
2006-12-18 16:01
冰河世纪
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:2167
专家分:0
注 册:2006-11-7
得分:0 

Dim a(19) As Integer

Dim i, j As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mystr As String
mystr = ""
For i = 0 To 19
Randomize()
a(i) = Int(90 * Rnd() + 10)
mystr = mystr & a(i) & Space(2)
If i = 9 Then
mystr = mystr & vbCrLf
End If
Next
TextBox1.Text = mystr
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s() As Object
Dim k As Integer
Dim mystr As String = ""
Static m As Integer
For i = 0 To 19
If a(i) Mod 2 <> 0 Then
m = m + 1
End If
s(m) = a(i)
Next
For i = 0 To m - 2
For j = i + 1 To m - 1
If s(i) > s(j) Then
k = s(i)
s(i) = s(j)
s(j) = k
End If
Next
Next
For i = 0 To m
mystr = mystr & s(i)
Next
MsgBox(mystr, , "从小到大")
End Sub


冰一样的少年,外表是冰,冷酷而强大;内心是冰,却一暖成水,柔柔漫漫
2006-12-22 16:42
zyp50725405
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-11-18
得分:0 
版主太厉害了
2006-12-22 19:04
zyp50725405
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-11-18
得分:0 

我想问一下为什么vb.net没c#.net的执行速度快,这是个问题啊!

2006-12-22 19:08
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
C#也算是的一个升级,呵呵.它借鉴了VB的一些优点.

飘过~~
2006-12-23 00:58
q81683280
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2006-10-31
得分:0 

Dim a(20) As Integer
Dim i, j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mystr As String
mystr = ""
For i =1 To 20
Randomize()
a(i) = Int(90 * Rnd() + 10)
mystr = mystr & a(i) & Space(2)
If i mod 5=0 Then
mystr = mystr & vbCrLf
End If
Next
TextBox1.Text = mystr
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
dim k ,temp as integer
dim str as string
for i= 1 to 19
k =i
for j= 2 to 20
if a(k)>a(j) then
k=j
next j
temp=a(i)
a(i)=a(k)
a(k)=temp
next i
for i= 1 to 20
if a(i) mod 2 <>0 then
str=str & a(i) & space(2)
if a(i) mod 5 =0 then
str=str & vbcrlf
end if
next i
msgbox("从小到大排列奇数:" & str )

end sub


小落 光交良友 QQ:359657069 http://q81683280./
2006-12-23 19:19
q81683280
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2006-10-31
得分:0 

不好意思
昨天不是在环境中写的
有点错误
今天把代码拷过来了

Dim a(20) As Integer
Dim i, j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mystr As String
mystr = ""
For i = 1 To 20
Randomize()
a(i) = Int(90 * Rnd() + 10)
mystr = mystr & a(i) & Space(2)
If i Mod 5 = 0 Then
mystr = mystr & vbCrLf
End If
Next
Textbox1.Text = mystr
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim k, temp As Integer
Dim str As String = ""
For i = 1 To 19
k = i
For j = i To 20
If a(k) > a(j) Then
k = j
End If
Next j
temp = a(i)
a(i) = a(k)
a(k) = temp
Next i
For i = 1 To 20
If a(i) Mod 2 <> 0 Then
str = str & a(i) & Space(2)
End If
Next i
MsgBox("从小到大排列奇数:" & Chr(10) & str)

End Sub


小落 光交良友 QQ:359657069 http://q81683280./
2006-12-24 17:15
xinsheng
Rank: 2
等 级:论坛游民
帖 子:43
专家分:15
注 册:2006-6-28
得分:0 
看不懂
Randomize()
有什么用呀?

2006-12-24 22:37
q81683280
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2006-10-31
得分:0 

Randomize()是为了使每次运行程序时生成的第一个随机数不相同~~~


小落 光交良友 QQ:359657069 http://q81683280./
2006-12-25 16:29
xinfresh
Rank: 4
等 级:贵宾
威 望:13
帖 子:594
专家分:0
注 册:2006-1-13
得分:0 
对以上解法提出一点建议:
既然做.net Framework下的程序,就最好不要再用Randomize,Rnd之类的6.0函数了
为什么不用Random类呢,又方便又强大

E-mail:xinfresh@QQ:383094053校内:http:///getuser.do?id=234719042
2007-01-01 16:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-110309-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048634 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved