1樓:
我已經上機驗證過了,正確。
思路:產生80個隨機數,把這80個隨機數由小到大排序,然後從第1個到第80個的順序挑選偶數,賦值給字串s1,夠10個換行 。
再從第80個到第1個的順序挑選奇數,賦值給字串s2,同上。
有一點很重要:把這兩個文字框的mutltiline屬性要改為 true
private sub command1_click()
dim s1, s2 as string
randomize
dim a(80) as integer
for i = 1 to 80
a(i) = 10 + int(rnd * 90)
next i
for i = 1 to 79
for j = i + 1 to 80
if a(i) > a(j) then t = a(i): a(i) = a(j): a(j) = t
next j
next i
n = 0
for i = 1 to 80
if a(i) mod 2 = 0 then
s1 = s1 + str(a(i))
n = n + 1
if n mod 10 = 0 then s1 = s1 + chr$(13) + chr$(10)
end if
next i
text1.text = s1
n = 0
for i = 80 to 1 step -1
if a(i) mod 2 <> 0 then
s2 = s2 + str(a(i))
n = n + 1
if n mod 10 = 0 then s2 = s2 + chr$(13) + chr$(10)
end if
next i
text2.text = s2
end sub
2樓:岔路程式緣
建立兩個文字框text1和text2,一個command1。注意(1)一定要把兩個文字框的mulltiline屬性改為true;(2)兩個文字框要足夠寬。
**如下:
private sub command1_click()
text1.text = "偶數從小到大排列"
text2.text = "奇數從大到小排列"
dim a(80) as byte, o(80) as byte, j(80) as byte
dim m as byte, n as byte
randomize
for m = 1 to 80
a(m) = int(rnd * 90 + 10)
if a(m) mod 2 = 0 then
o(0) = o(0) + 1
o(o(0)) = a(m)
else
j(0) = j(0) + 1
j(j(0)) = a(m)
end if
next
for m = 1 to o(0) - 1
for n = m + 1 to o(0)
if o(m) > o(n) then
a(0) = o(m)
o(m) = o(n)
o(n) = a(0)
end if
next
next
for m = 1 to j(0) - 1
for n = m + 1 to j(0)
if j(m) < j(n) then
a(0) = j(m)
j(m) = j(n)
j(n) = a(0)
end if
next
next
text1.text = text1.text + "(共有" + str(o(0)) + "個):" + vbcrlf
text2.text = text2.text + "(共有" + str(j(0)) + "個):" + vbcrlf
for m = 1 to o(0)
text1.text = text1.text + str(o(m))
if m mod 10 = 0 then text1 = text1.text + vbcrlf
next
for m = 1 to j(0)
text2.text = text2.text + str(j(m))
if m mod 10 = 0 then text2 = text2.text + vbcrlf
next
end sub
已經執行過。
3樓:
private sub command1_click()
dim i, a(1 to 80), b(), c(), j, k
randomize
text1.text = "隨機產生80個10~99之間的整數:" & vbcrlf
for i = 1 to 80
a(i) = int(rnd * 90) + 10
text1.text = text1.text & a(i) & " "
if i mod 10 = 0 then text1.text = text1.text & vbcrlf
if a(i) mod 2 = 0 then
redim preserve b(j)
b(j) = a(i)
j = j + 1
else
redim preserve c(k)
c(k) = a(i)
k = k + 1
end if
next
for i = 0 to ubound(b)
for j = 0 to i
if b(i) < b(j) then t = b(i): b(i) = b(j): b(j) = t
next
next
for i = 0 to ubound(c)
for j = 0 to i
if c(i) > c(j) then t = c(i): c(i) = c(j): c(j) = t
next
next
text1.text = text1.text & "由小到大排序的偶數:" & vbcrlf
for i = 0 to ubound(b)
text1.text = text1.text & b(i) & " "
if (i + 1) mod 10 = 0 then text1.text = text1.text & vbcrlf
next
text1.text = text1.text & vbcrlf & "由大到小排序的奇數:" & vbcrlf
for i = 0 to ubound(c)
text1.text = text1.text & c(i) & " "
if (i + 1) mod 10 = 0 then text1.text = text1.text & vbcrlf
next
end sub
4樓:
private sub command1_click()
dim odd() as integer, even() as integer, i as integer, j as integer, k as integer, d as integer
randomize
redim odd(80)
redim even(80)
j = -1
k = -1
for i = 1 to 80
d = int(rnd * (99 - 10 + 1)) + 10
if d mod 2 = 0 then
k = k + 1
even(k) = d
else
j = j + 1
odd(j) = d
end if
next
redim preserve odd(j)
redim preserve even(k)
for i = 0 to ubound(even)
for j = i to ubound(even)
if even(j) < even(i) then
d = even(i)
even(i) = even(j)
even(j) = d
end if
next
next
text1.text = ""
for i = 0 to ubound(even)
text1.text = text1.text & even(i) & " "
if right(i, 1) = "9" then text1.text = text1.text & vbcrlf
next
for i = 0 to ubound(odd)
for j = i to ubound(odd)
if odd(j) > odd(i) then
d = odd(i)
odd(i) = odd(j)
odd(j) = d
end if
next
next
text2.text = ""
for i = 0 to ubound(odd)
text2.text = text2.text & odd(i) & " "
if right(i, 1) = "9" then text2.text = text2.text & vbcrlf
next
end sub
5樓:蘇州老三石
'為你量身定做的:
private sub command1_click()
randomize
dim i as integer, tem as integer
dim a() as integer, m as integer
dim b() as integer, n as integer
text1.text = ""
text2.text = ""
for i = 1 to 80
tem = int((89) * rnd + 10)
if tem mod 2 = 0 then
m = m + 1
redim preserve a(m)
a(m) = tem
else
n = n + 1
redim preserve b(n)
b(n) = tem
end if
next
dim j as integer
dim k as integer
for i = 1 to ubound(a) - 1
for j = i + 1 to ubound(a)
if a(i) > a(j) then
tem = a(i)
a(i) = a(j)
a(j) = tem
end if
next
next
j = 0
for i = 1 to ubound(a)
j = j + 1
if j mod 10 = 0 then text1.text = text1.text & chr(10) + chr(13)
text1.text = text1.text & a(i) & " "
next
for i = 1 to ubound(b) - 1
for j = i + 1 to ubound(b)
if b(i) < b(j) then
tem = b(i)
b(i) = b(j)
b(j) = tem
end if
next
next
j = 0
for i = 1 to ubound(b)
j = j + 1
if j mod 10 = 0 then text2.text = text2.text & chr(10) + chr(13)
text2.text = text2.text & b(i) & " "
next
end sub
vb中利用隨機函式產生100到999之間的整數構
和bai 1 樓不一 du樣,zhi我dao用到版 了權 text框 private sub mand1 click dim a 1 to 25 as integerdim i as integer text1.text for i 1 to 25 randomize a i int 900 rnd...
急求vb程式設計「利用隨機函式產生50 100之間的隨機整
private sub command1 click randomize n rnd 10 for i 1 to n s s i a a 1 s 這裡應該注意!next msgbox n值為 str n 結果為 str a end sub 你沒給分啊 吃白飯,不行咧 計算機vb中,利用隨機函式產生1...
利用隨機函式產生兩位整數,怎麼按從大到小的順序排序輸出
include include include using namespace std int main for int i 0 i 10 i for int j 0 j 9 i j if a j import random a range 10,100 b random.sample a,10 b...