用vb做產生20 100的隨機整數,求出這些數的最大值 最小值和平均值

時間 2022-12-06 15:40:56

1樓:宇桐非吧外交

dim a(1 to 20) as integerprivate sub command1_click()clsscale (0, 0)-(100, 100)for u = 1 to 20

a(u) = int(rnd * 50) + 50b = b + a(u)

print a(u)

next u

c = b / 20

for i = 1 to 19

for j = i + 1 to 20

if a(i) > a(j) then temp = a(i): a(i) = a(j): a(j) = temp

next j

next i

currentx = 10: currenty = 20print "最大值為" & a(20) & " " & "最小值為" & a(1) & " " & "平均值為" & c

end sub

我試過的 沒問題 你看看,有疑問再聯絡我!!

2樓:匿名使用者

private sub command1_click()dim 數%, 最大值%, 最小值%, 平均值%, 和%最小值 = 9999

for i = 1 to 20

數 = rnd * 50 + 0.5 + 50print 數;

if 數 > 最大值 then 最大值 = 數if 數 < 最小值 then 最小值 = 數和 = 和 + 數

next i

平均值 = 和 / 20

print

print "最小值:" & 最小值

print "最大值:" & 最大值

print "平均值:" & 平均值

end sub

用vb求最大值最小值和平均值

輸入n個 數,求出它們的最大值,最小值和平均值?用vb怎麼編寫程式

3樓:匿名使用者

1.你用自己的方法將這n個數字分別用陣列a(1)-a(n) 表示2.求最大

for i= 1 to n-1

if a(i)>a(i+1) then

max=a(i)

else

max=a(i+1)

endif

next i

3.求最小。用類似的方法

4.求平均值:

for i=1 to n

all=all+a(i)

next i

prv=all/n

4樓:

數字的輸入只是一種方法,你可以用其他你認為方便的方法

private sub command1_click()

dim x, y, z, a, jh, num() as double

x = 1

do while x > 0

x = instr(x + 1, text1.text, ",")

if x > 0 then

redim preserve num(y + 1)

if y = 0 then

num(y) = val(mid(text1.text, 1, x - 1))

else

num(y) = val(mid(text1.text, z, x - 1))

end if

y = y + 1

z = x + 1

end if

loop

for x = 0 to y

z = z + num(x)

for a = 0 to y

if num(x) < num(a) then

jh = num(x)

num(x) = num(a)

num(a) = jh

end if

next a

next x

label2.caption = "最大值為:" & num(y) & " 最小值為:

" & num(1) & " 平均數為:" & format(z / y, "#.00")

end sub

private sub form_load()

text1.text = ""

label1.caption = "請在文字框中輸入需要排序的數 用,分隔每個數字並以,結尾"

label1.autosize = true

label2.caption = ""

label2.autosize = true

msgbox "請在文字框中輸入需要排序的數 用,分隔每個數字並以,結尾"

end sub

5樓:

用冒泡法 求最大 和 最小的數 平均更簡單 相加/n

我臨時有點事情 沒時間去寫**給你了 你自己去看看 自己能解決的 不難

用VB做簡單的小程式,用VB做乙個簡單的小程式

private sub command1 click me.cls dim n as integer,i as integern inputbox n 9 for i 1 to 2 n 1if i n then print space n i string 2 i 1,cstr i else pri...

怎樣用VB做最簡單的時鐘,怎樣用VB做乙個最簡單的時鐘?

在窗體上畫乙個label和乙個計時器,寫下如下 即可。private sub form load timer1.interval 2000timer1.enabled truelabel1.caption timeend sub private sub timer1 timer label1.cap...

怎麼用VB打九九乘法表,用VB程式怎麼做九九乘法表?

三角形的九九乘法表 private sub form load dim i,j,s for i 1 to 9 for j 1 to i s s j i iif len i j 2,i j i j next s s vbcrlf next msgbox s end sub private sub 確定...

vb裡這個怎麼做,vb主要是做什麼用的

c語言要想學好還是很難的!vc和c 倒是和vb差不多難度。vb是高階語言,c語言是介於高階語言和低階語言之中的一種語言,所以功能要比vb和vc大多了 個人認為 要想成為高手,組合語言還是必不可少的!vb是微軟公司開發的一種程式語言,大部分語義借鑑了basice的語句,但實現了圖形化程式設計介面,並實...

誰能解答 VB中隨機產生2位數,按從大到小的順序排列

private sub form click dim a 1 to 10 randomize timer for i 1 to 10 a i int rnd 90 10 print a i next i for i 1 to 9 for j i 1 to 10 if a i a j then c a...