vb2010寫的:
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、廣元ssl等。為上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的廣元網(wǎng)站制作公司
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個(gè)隨機(jī)數(shù)字是?"??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??粗肢孝"排序后的數(shù)字是?"??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
運(yùn)行結(jié)果:
生成的30個(gè)隨機(jī)數(shù)字是
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
排序后的數(shù)字是
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
用不到2個(gè)命令按鈕 1個(gè)就夠
在按鈕的過程中寫如下代碼
dim x as long , y as long ,z as long ,j as long ,n as long
dim k as integer
x = val(text1.text)
y = val(text2.text)
z = val(text3.text)
j = val(text4.text)
if x = then k = k+1
if y= then k = k+1
if z= then k = k+1
if j= then k = k+1
' 若輸入的數(shù)有負(fù)數(shù)舉清 則必須先在這里寫正模前下 n=-.....()
do
if x 0 and n = x then
text5.text = text5.text " " x
k = k +1
end if
if y 0 and n = then
text5.text = text5.text " " y
k = k +1
end if
if z 0 and n = z then
text5.text = text5.text " " z
k = k +1
end if
if j 0 and n = j then
text5.text = text.text "碼汪 " j
k = k +1
end if
if k = 4 then exit for
n=n+1
loop
這是VB的代碼。。。。 不知道點(diǎn)虐 適用不
'vb點(diǎn)虐 2008
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) '衡仔復(fù)制數(shù)組
System.Array.Sort(b) '排序,數(shù)組b就是虛枝小咐譽(yù)汪到大的排列
End Sub
End Class
舉個(gè)例子:比較a,b,c,d四個(gè)數(shù)字的大小,取Xmin=最小的數(shù)字。神基段例如:1,2,3,4,則Xmin=1;如果1,2,0,3,則Xmin=1,全為0時(shí),Xmin=0
新建一個(gè)工程
上面建成一個(gè)text1再復(fù)制三個(gè),生成了個(gè)控件數(shù)據(jù)
再搞一按鈕,復(fù)制下面的代碼就可以了,游譽(yù)測(cè)試沒有問題,
Dim a(4) ‘定義數(shù)組
Private Sub Command1_Click()
For j = 1 To 4
a(j) = Text1(j - 1).Text ’這里為了簡單我就用數(shù)組控件了
Min = a(1)
flag = 1
For i = 2 To 4
a(i) = Text1(i - 1).Text
If Min a(i) Then
If Min = 0 Then
Min = a(i)
End If
If a(i) = 0 Then
Min = Min
End If
Min = a(i)
flag = i
End If
Next i
Next j
MsgBox Min
End Sub
測(cè)試沒有問題哦……
如果不想用控件數(shù)組的請(qǐng),建四個(gè)文本框,寫上a(1) = Text1.Text
a(2)=text2.text…鋒或………