VB題 定義陣列,包含兩位的隨機整數,求出其中的最大

2022-01-02 07:39:08 字數 4669 閱讀 3511

1樓:匿名使用者

private sub form_click()dim a(1 to 10) as integerprint "原始資料是:"

for k = 1 to 10

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

next k

max = a(1)

print

print "最大數是:"

for each x in a

if max < x then

max = x

end if

next x

print max

end sub

2樓:匿名使用者

直接將下面**複製到窗體中測試即可private sub form_activate()

dim a(10) as integer

dim k as integer

dim max as integer

me.cls

print "隨機資料如下:"

max = 0

randomize

for k = 1 to 10

a(k) = int(90 * rnd + 10)print a(k) & " ";

if a(k) > max then

max = a(k)

end if

next

print vbcrlf & "10個隨機數中最大的數是:" & vbcrlf & max

end sub

3樓:匿名使用者

private sub command1_click()clsdim a(1 to 10) as integerdim i as integer, max as integerrandomize

a(1) = rnd * 90 + 10

max = a(1)

for i = 2 to 10

a(i) = (rnd * 90 + 10)if max < a(i) then max = a(i)next i

print "陣列";

for i = 1 to 10

print a(i);

next i

print

print "最大數是" & max

end sub

vb題,用隨機函式生成包含10個兩位整數的一維陣列,求這10個數的最大值,最小值以及平均值。

4樓:匿名使用者

執行結果:

生成的陣列為

73 58 62 36 37 79 11 78 83 73排序後的陣列為

83 79 78 73 73 62 58 37 36 11該陣列元素各個元素的和是 590 最大元素是 83 最小元素是 11

vb產生30個0~1000的隨機整數,放入一個陣列中,輸出最大值

5樓:兄弟連教育北京總校

'實現**如下

private sub form_click()me.cls

dim n(1 to 30) as integerdim i%,nmax%

dim str as string

'產生30個0-1000的隨機數並寫入陣列randomize

for i = 1 to 30

n(i) = int((1000 - 0 + 1) * rnd + 0)

str = str & n(i) & " "

if i mod 10=0 then str=str & vbcrlf

next i

'找最大值

nmax=n(1)

for i = 1 to 30

if n(i)>nmax then nmax=n(i)next i

print str '窗體顯示隨機數

print "最大值:" & nmax

end sub

vb試題用隨機函式產生 10個兩位數的整數放在陣列a中並輸出,用隨機函式產生10個一位數的整數放入數

6樓:匿名使用者

新建一bai工程,在窗體上拖入一ducommand控制元件。然後進zhi入**區

dao,刪除所有**後,粘內貼以下**即容可。

option explicit

private sub command1_click()dim a(9) as integer, b(9) as integer, c(9) as integer

dim i as integer

randomize

clsprint "陣列a", "陣列b", "陣列c"

for i = 0 to 9

a(i) = rnd() * 9 + 10 '產生隨機兩位整數b(i) = rnd() * 9      '產生隨機一位整數c(i) = a(i) + b(i)    '將對應的隨機數相加print a(i), b(i), c(i) '結果輸出到窗體上next i

end sub

執行效果如下圖所示:

vb隨機10個兩位整數,找出其中最大,最小值

7樓:聽不清啊

private sub command1_click()randomize

max = 0

min = 100

print "10個隨機整數為:"

for i = 1 to 10

x = int(rnd * 90) + 10print x;

if x > max then max = xif x < min then min = xnext i

print

print "最大值:"; max

print "最小值:"; min

end sub

vb隨機產生10個任意的兩位正整數存放在一維陣列中,求陣列的最大值、平均值、能實現將資料升序排列,並且

8樓:

option base 1

option explicit

dim a(11) as integer

private sub command1_click()

dim i as integer

picture1.cls

picture1.print "產生的一維陣列為:"

randomize

for i = 1 to 10

a(i) = int(rnd * 20 + 10)

picture1.print a(i);

next i

picture1.print

end sub

private sub command2_click()

dim max as integer, p as integer, i as integer

for i = 1 to 10

if max < a(i) then max = a(i)

next

picture1.print "最大值為:" & max

end sub

private sub command3_click()

dim p as integer, i as integer, sum as integer

for i = 1 to 10

sum = sum + a(i)

next

picture1.print "平均值為:" & cstr(sum / 10)

end sub

private sub command4_click()

dim i as integer, m as integer, b(10) as integer, j as integer

for i = 1 to 10

b(i) = a(i)

next i

for i = 10 to 1 step -1

for j = 1 to i - 1

if b(j) > b(j + 1) then

m = b(j + 1)

b(j + 1) = b(j)

b(j) = m

end if

next j

next i

picture1.print "陣列按從大到小排序:"

for i = 1 to 10

picture1.print b(i);

next

end sub

private sub command5_click()

dim x%, p%, i%

x = val(inputbox("輸入要插入的資料:"))

p = 1

do while x > a(p) and p <= 10

p = p + 1

loop

for i = 10 to p step -1

a(i + 1) = a(i)

next i

a(p) = x

picture1.print

picture1.print "插入後的一維陣列為:"

for i = 1 to 11

picture1.print a(i);

next i

end sub

vb程式設計定義包含元素的陣列a,為其陣列元素分別賦值為 20,並將其輸出

private sub command1 click dim a 10 as integer for i 1 to 10 a i 2 i print a i next i end sub vb程式設計宣告一個有10個元素的一維陣列a使用inputbox函式為所有元素賦值,將其最小元素的值及下標顯示出...

VB逐行取最後兩位

private sub command1 click dim grp as string 把text1.text放到陣列中,每一行為一個元素值,迴圈擷取grp split text1.text,vbcrlf dim i as long text2.text for i 0 to ubound grp...

保留兩位有效數字和保留兩位小數的區別

首先要理解有效數 字的概念,有效數字是指從左邊第一位不是0的數開始計數,比如,0.0023,它的有效數字是兩位,另外解釋下保留兩位小數和保留兩位有效數字的區別,同樣舉例說明 1.0023,保留兩位小數,則為1.00,小數點後面取兩位。保留兩位有效數字,則為1.0,第一個不是0的數開始取兩位.這個是整...