設計VB程序,將陣列元素排序,設計乙個VB程式,將陣列元素排序

時間 2022-09-17 15:35:07

1樓:匿名使用者

private sub command1_click()dim a()

dim n as integer

randomize

n = int(5 * rnd) + 5 'n的範圍為:5~9 ,是生成隨機數的個數

redim a(n)

for i = 1 to n

a(i) = int(rnd * 900) + 100 '隨機的三位整數

next

text1.text = trim(join(a, " "))for i = 1 to n

for j = i + 1 to n

if a(i) > a(j) then

t = a(i)

a(i) = a(j)

a(j) = t

end if

next

next

text2.text = trim(join(a, " "))end sub

2樓:

看不出來是乙個題,還是兩個題目。

按乙個題目做吧。

private sub paixu(x() as single)for i = 0 to ubound(x) - 1for j = i + 1 to ubound(x)if x(i) > x(j) then

t = x(i)

x(i) = x(j)

x(j) = t

end if

next j

next i

end sub

private sub command1_click()dim a

a = split(text1, ",")paixu a()

text2 = a(0)

for i = 1 to ubound(a)text2 = text2 & "," & str(a(i))next i

end sub

private sub form_load()text1 = ""

text2 = ""

end sub

設計vb程式,將二維陣列中每一列的元素從小到大排序

3樓:聽不清啊

private sub command1_click()dim a(10, 10) as integerrandomize

print "原來的陣列:"

for i = 1 to 10

for j = 1 to 10

a(i, j) = rnd * 100

print format(a(i, j), "@@@");

next j

print

next i

for j = 1 to 10

for i = 1 to 9

for i1 = 1 to 10 - j

if a(i1, j) > a(i1 + 1, j) thent = a(i1, j): a(i1, j) = a(i1 + 1, j): a(i1 + 1, j) = t

end if

next i1

next i

next j

print

print "排序後的陣列:"

for i = 1 to 10

for j = 1 to 10

print format(a(i, j), "@@@");

next j

print

next i

end sub

vb 編寫乙個能對一維陣列進行公升序排列的子程式過程!

4樓:慶年工坊

sub s(arr&())

n = ubound(arr)

for i = l + 1 to n

for j = n to i step -1if arr(j) < arr(j - 1) thentmp = arr(j)

arr(j) = arr(j - 1)

arr(j - 1) = tmp

end if

next

next

end sub

5樓:聽不清啊

private sub command1_click()dim a(20) as integer

for i = 1 to 20

a(i) = int(100 * rnd)print a(i);

next i

call sort(a, 20)

print

print

print "排序以後:"

for i = 1 to 20

print a(i);

next i

end sub

sub sort(a() as integer, n as integer)

for i = 1 to n - 1

for j = 1 to n - i

if a(j) > a(j + 1) thent = a(j): a(j) = a(j + 1): a(j + 1) = t

end if

next j

next i

end sub

6樓:張程通

'氣泡排序,最簡單的排序演算法,下面這個子過程是對integer型別的陣列公升序排序,如果需要其他型別的資料,可以將其中的integer替換掉

sub maopaosort(a() as integer)dim i as integer

dim j as integer

dim temp as integer

for i = lbound(a()) to ubound(a()) - 1

for j = lbound(a()) to ubound(a()) - 1

if a(j) > a(j + 1) thentemp = a(j)

a(j) = a(j + 1)

a(j + 1) = temp

end if

next

next

end sub

vb,用氣泡排序法實現對陣列中含有10個元素(隨機產生)的一維陣列進行公升序排列

7樓:匿名使用者

這個要動態演示排序過程麼?還是直接顯示排序的結果?

8樓:

private sub command1_click()dim a(1 to 10) ,i ,j,s as integerrandomize

for i=1 to 10 //隨機10個產生1-100的整數

a(i) = int(rnd * 100) + 1next i

for i=1 to 9

for j=i+1 to 10

if a(i)>a(j) then //如果前面的比後面大,那麼就讓他們交換

s=a(i)

a(i)=a(j)

a(j)=s

end if

next j

next i

for i=1 to 10

print a(i)

next i

end sub

有什麼不明白的,可以追問。

9樓:匿名使用者

dim n(9) as integer

for i = 0 to 9

randomize '初始化

n(i) = rnd * 100 '賦隨機值next i

dim temp as integer '用作改變位置臨時儲存for i = 0 to 8

if n(i) > n(i + 1) then '判斷是否前一位大於後一位

temp = n(i)

n(i) = n(i + 1)

n(i + 1) = temp

i = -1 '為了更準確,讓它重新開始

end if

next i

for i = 0 to 9

print "第" & i + 1 & "位:" & n(i) '輸出

next i

vb程式題:分別用氣泡排序法實現有n個元素陣列的排序。n由鍵盤輸入,陣列元素的值在1~200之間,隨機產生

vb編寫隨機產生乙個陣列,並且將陣列元素逆序存放。(一維陣列)

10樓:匿名使用者

逆序:從大到小,還是,從小到大,還是什麼?

11樓:匿名使用者

private sub command8_click()dim b(0 to 10) as integer, mp as integer, i as integer, x as integer

randomize

for i = 0 to 10

b(i) = int(rnd * (100 - 1 + 1) + 1)

print b(i)

next

print

for i = 0 to ubound(b)for x = i + 1 to ubound(b)if b(x) > b(i) then

mp = b(i)

b(i) = b(x)

b(x) = mp

end if

next

print b(i)

next

end sub

vb程式編寫:某陣列有20個元素,元素的值由鍵盤輸入,要求將前10個元素與後10個元素對換。高分懸賞

12樓:匿名使用者

dyeb @@@cfsx 19d si

13樓:古龍珈藍玉

vb程式設計的輸入編寫的時候要注意寫作速度,元素,v的輸入

用VB設計IP判斷的程式,用VB設計乙個IP判斷的程式

設文字框t1,t2,t3 private sub command1 click dim ip1 dim ip2 dim ip3 ip1 toip t1.text ip2 toip t2.text ip3 toip t3.text if ip1 and ip3 ip2 and ip3 then msg...

用VB迴圈巢狀結構設計一程式,用VB迴圈巢狀結構設計一程式

哥,看不到你的鏈結,說是圖形外部鏈結受限。我也不清楚了,這些只是 以下的 只是死迴圈,用於任何乙個控制項!開始和結束的 我省略了,把 複製在中間就可以了!while和msgbox後面的數字可以是任何數,都一樣的 while 2 msgbox 2 wend 看不到圖,重給個能看的鏈結吧 關於vb兩重迴...

求乙個簡單的VB程式 高手 速度啊

首先新建乙個標準工程,在窗體中新增乙個command1命令按鈕,在其中加入下面 private sub command1 click dim a 9 as integer 定義乙個陣列,存放十個兩位數。dim n as integer 用於迴圈十次。dim sum as integer 存放元素之和...