vb排序問題

2023-02-07 17:20:40 字數 873 閱讀 2533

1樓:吾桐語

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

for i = 1 to 20

randomize

a(i) = int(rnd * 90) + 10next i

for i = 1 to 19

for j = i + 1 to 20

if a(i) > a(j) then

r = a(i)

a(i) = a(j)

a(j) = r

end if

next j

next i

for i = 1 to 20

print a(i);

next i

end sub

2樓:小木屋

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

print "排序前"

for i = 1 to 20

randomize

a(i) = int(rnd * 90) + 10print a(i);

next i

print

for i = 1 to 19

for j = i + 1 to 20

if a(i) > a(j) then

r = a(i)

a(i) = a(j)

a(j) = r

end if

next j

next i

print "排序後"

for i = 1 to 20

print a(i);

next i

end sub

vb陣列排序程式設計不排序

你的程式是完成隨機生成10個兩位整數,然後按由小到大排序,你用的是氣泡排序法。你的程式迴圈裡面的n沒有賦值,即在for j 1 to n 1這條語句前,給n加一個賦值語句 n 10。程式如下 private sub command1 click dim a 1 to 10 as integerdim...

vb隨機數排序

在窗體中建立三個picture控制元件,並拉伸到適當大小,框中新增如下 執行點選窗體即可。private sub form click dim a 1 to 60 as integer,o 1 to 60 as integer,ji 1 to 60 as integer randomize num1...

VB的簡單氣泡排序

原因有二,一是你沒把變數賦值 因此輸出全是0 二是你的程式有些錯誤,應該是a i 而不是a 1 下面為修改後的程式。private sub command1 click dim a 30 as integer dim i,j,tem as integerconst n 30 給a i 賦值 for ...