vb隨機生成數並顯示在文字框中,並找出最大數,指出它的位置

時間 2022-02-13 18:37:41

1樓:匿名使用者

var str=""

for i as integer =0 to 9randomize()

dim r as int= cint(rnd() * 1)str&=cstr(r)

next

textbox1.text=str

var sz=str.tochararray().max()var wz=str.indexof(sz)msgbox("最大數字" & sz & "在" & wz)

2樓:匿名使用者

新增乙個text1,輸入以下**,然後執行。單擊窗體,十個隨機數顯示在text1中,彈出對話方塊,提示第幾個為最大數,並將最大數選中。

private sub form_click()dim a(1 to 10) as integer, i as integer

randomize

for i = 1 to 10

a(i) = int(rnd * 90) + 10text1.text = text1.text & space(2) & a(i)

next

max = a(1)

for i = 1 to 10

max = iif(max >= a(i), max, a(i))next

for i = 1 to 10

if a(i) = max then

msgbox "最大數為第" & i & "個"

text1.setfocus

text1.selstart = i * 4 - 2text1.sellength = 2

end if

next

end sub

private sub form_load()text1.text = ""

end sub

3樓:啊彈

這個不難啊,不過我不會,不好意思樓主.

4樓:沙慧月

private sub command1_click()dim max1, wz as integerfor i = 1 to 10

randomize

text1 = text1 & int(rnd * 100 + 1) & space(1)

next

t = split(text1, " ")max1 = t(0)

wz = 1

for i = 1 to ubound(t) - 1if val(t(i)) > max1 thenmax1 = val(t(i))

wz = i + 1

end if

next

print "最大值為" & max1 & "," & "位置為:" & wz

end sub

寫vb程式:隨機生成10個數,儲存在一維陣列中,顯示最大數及位置

5樓:匿名使用者

private sub command1_click()randomize timer

dim i as integer, a(9) as integerdim maxn as integer, maxi as integer

for i = 0 to 9

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

if maxn < a(i) then

maxn = a(i)

maxi = i

end if

next

print

print "最大數是:" & maxn & " 位置是:" & maxi + 1

end sub

6樓:匿名使用者

private sub form_paint()dim a(1 to 10) as doubledim i as integer, n as integer, m as double

m = 0

randomize

for i = 1 to 10

a(i) = rnd

if m < a(i) then

m = a(i)

n = i

end if

print i, a(i)

next

print

print

print "第", n, m, "最大"

end sub

vb隨機產生10個兩位數,並找出最大數和最小數,顯示出來

7樓:匿名使用者

private sub form_click()cls '清除螢幕

dim a as integer '定義 a 為整形a = val(inputbox("請決定需要排多少組組數值?", "排序數值數")) 'a的等於輸入框所返回的數值,決定排序陣列的個數

dim i(100) '定義i 為陣列 ,100個元素 (每個元素都是整形的變數)

for j = 1 to a

i(j) = val(inputbox("請輸入第" & j & "組數值", "輸入資料")) '為每個陣列賦值

print i(j) ' 列印每組陣列的值next j '結束for迴圈

print " -----------------排序結果"

for j = 1 to a

for k = j + 1 to a

if i(j) > i(k) then

p = i(j)

i(j) = i(k)

i(k) = p

end if

next k

next j

for j = 1 to a

print i(j) '列印出排序過的陣列next

end sub

8樓:平野川

private sub form_click()

randomize() '初始化隨機數生成器,產生不重複的偽隨機數。

dim a(9) as integer, max as integer, min as integer

max = 0

min = 99

for i = 0 to 9

a(i) = int(rnd() * 89 + 10) ' 產生10-99的10個兩位隨機數

if a(i) >= max then max = a(i) '比較求最大值

if a(i) <= min then min = a(i) '比較求最小值

print a(i); '輸出產生的10個兩位隨機數

next i

print("max=" & max) '輸出最大值

print("min=" & min) '輸出最小值

end sub

vb程式設計問題:1使用隨機函式產生10個10~100之間的隨機整數存放在一維陣列a中,並把該陣列排序後顯示在乙個

9樓:匿名使用者

根據已有的程式行,缺的內容主要就是乙個排序過程。新增乙個排序的過回

程就答行了。但是不知道該添在**,請說明程式的空白處是在**?能不能標出來,比如用括號,星號什麼的,標一下需要補充到**?

或者,能不能說明一下,各文字框,按鈕的功能是什麼? d = val(text3.text),這個應該是要插入的資料了,說明text3是用來輸入的,text2.

text = text2.text & str(a(i)),這說明text2是顯示排序後的結果的,

那有沒有text1?用作什麼?兩個按鈕定義的功能是什麼?插入的資料怎麼插?是隨機插入乙個位置,並替換掉原來的資料還是將陣列重新定義隨機插入後,後面的數向後移?

這些需要說明一下,或者把需要填寫的位置標清楚,不然,不好確定該怎麼填。

vb隨機產生10個10-100之間的數,找到其中最大的和最小的數的位置並對調

10樓:張程通

在窗體上新增乙個command1按鈕

private sub command1_click()

dim i as integer

dim maxno as integer, max as integer

dim minno as integer, min as integer

dim num(1 to 10) as integer

dim temp as integer

for i = 1 to 10

randomize

num(i) = int(rnd * 91 + 10)

next

max = num(1)

maxno = 1

min = num(1)

minno = 1

for i = 1 to 10

if num(i) < min then

min = num(i)

minno = i

end if

if num(i) > max then

max = num(i)

maxno = i

end if

next

clsprint "隨即產生的10個10到100的數為:"

for i = 1 to 10

print num(i);

next

print

print "其中第" & maxno & "個數" & max & "是最大數,"

print " 第" & minno & "個數" & min & "是最小數,"

temp = num(maxno)

num(maxno) = num(minno)

num(minno) = temp

print "交換最大數與最小數之後為:"

for i = 1 to 10

print num(i);

next

end sub

樓主如果覺得還有什麼問題儘管補充

vb程式設計:隨機生成10個互不相同的1~100之間的整數,存放在一維陣列中,找出最大的元素,並從陣列中刪除該元素

11樓:匿名使用者

dim i as integer

dim s(10) as integer

dim max as integer

for i = 0 to 9

randomize

s(i) = int(rnd * 100) + 1if i = 0 then

max = s(i)

elseif max < s(i) thenmax = s(i)

end if

debug.print max & " " & s(i)next i

刪除的我沒有寫,你自己擴充套件吧。。最大的數儲存的max 中。s(i)隨機數儲存的陣列

12樓:dobby丶丁

int a[10],max,i; max=a[0]; for(i=0;i<10;i ) if(a[i]==max) a[i]=a[i 1];

13樓:匿名使用者

option explicit

private a(9) as integerprivate imaxindex as integerprivate sub command1_click()dim i, j, k, imax as integerdim b as boolean

randomize

b = true

i = 0

imax = 0

imaxindex = 0

clsdo while b

k = int(rnd * 100) + 1for j = 0 to i

if k = a(j) then exit fornext j

if j > i then

a(i) = k

if k > imax then

imax = k

imaxindex = i

end if

i = i + 1

b = (not (i > 9))

print k

end if

loop

print "最大:" & str(imax)end sub

private sub command2_click()dim i as integer

a(imaxindex) = 0

for i = 0 to 9

print a(i)

next i

end sub

vb題目 單擊「生成隨機數」按鈕,隨機生成兩3位正整數M N分別顯示在對應文字框中

使用 random類 可以實現。private sub button1 click sender as object,e as eventargs handles button1.click dim newrandom1 as new random dim newrandom2 as new ran...

用vb語言編寫程式隨機生成兩個,用vb語言編寫乙個程式,隨機生成兩個100 300之間的正整數,顯示他們,並求這兩個數的最大公約數

瘋狂小鳥 如圖所示,望採納。 冉冉曦丶 imports system.math public class form1 private sub button1 click sender as object,e as eventargs handles button1.click dim a,b as ...

vb隨機函式,vb隨機函式

dim a 1 to 35 randomize for i 1 to 35 a a i int rnd 36 for j 1 to i 1 if a i a j then goto anext j next i 請參考這個題我的回答 同樣是關於vb隨機數生成的。這很簡單 以窗體click事件為例 d...

用vb編寫程式隨機生成1099互不相同的整數將

好吧,沒有研究過。不過用隨機函式加氣泡排序法應該可以做出來的吧。同求,希望高手們寫注釋啊!private sub command1 click clsdim a 1 to 10 as integerfor i 1 to 10 randomize a i int rnd 90 10 for j 1 t...

vb程式設計,產生隨機數,vb程式設計,產生隨機數

可以的,先設定textbox的屬性值,確定範圍,隨機數產生用 rnd函式。比如 int rnd 整數n 產生0,1,2,3,n 1中的隨機數。rnd產生的是0 1的隨機數。例如 int rnd n m 1 m 產生的是在區間 m,n 內的數。randomize 關鍵必須有,不然每次執行隨機數都不變n...