1樓:匿名使用者
private sub form_click()dim a(4) as single,i as integer,j as integer
for i=1 to 3
for j=i+1 to 4
if a(i) > a(j) then
a(0) = a(j)
a(j) = a(i)
a(i) = a(0)
next
next
print "從大到小的順序是:"
print a(1),a(2),a(3),a(4)end sub
2樓:匿名使用者
因為我也是新手,所以我用最苯的方法
首先在窗體上準備6個文字框,一個命令按紐,3個標籤。其中4個文字text1到text4用來輸入資料,另外2個文字text5和text6用來顯示最大和最小值,2個標籤分別對應這2個文字
**如下
private sub command1_click()
dim a(3) as double, max as double, min as double
a(0) = text1.text: a(1) = text2.text: a(2) = text3.text: a(3) = text4.text
if a(0) < a(1) then max = a(1): min = a(0) else max = a(0): min = a(1)
if max < a(2) then max = a(2)
if max < a(3) then max = a(3)
if min > a(2) then min = a(2)
if min > a(3) then min = a(3)
text5.text = max: text6.text = min
end sub
private sub form_load()
text1.text = ""
text2.text = ""
text3.text = ""
text4.text = ""
text5.text = ""
text6.text = ""
label1.caption = "最大數"
label2.caption = "最小數"
end sub
vb求一組數的最小值和最大值
3樓:網海1書生
option base 1
private sub f(a() as integer, max as integer, min as integer)
dim i as integer
max = a(1)
min = a(1)
for i = 2 to ubound(a)if max < a(i) then max = a(i)if min > a(i) then min = a(i)next i
end sub
private sub command1_click()dim a(10) as integer, n as integer, max as integer, min as integer
randomize
text1.text = ""
for n = 1 to 10
a(n) = int(100 * rnd)text1.text = text1.text & a(n) & " "
next
f a, max, min
text2.text = max
text3.text = min
end sub
4樓:
option base 1
private sub command1_click()
dim a() as integer, n as integer, max as integer, min as integer
text1.text = " "
text2.text = " "
text3.text = " "
randomize
for n = 1 to 10
a(n) = int(100 * rnd)
text1.text = text1.text & a(n) & " "
next
call f(a(),max,min)
text2.text = max
text3.text = min
end sub
private sub f(a() as integer, max as integer, min as integer)
dim i as integer
max = a(1)
min = a(1)
for i = 2 to ubound(a)
if max < a(i) then max = a(i)
if min > a(i) then min = a(i)
next i
end sub
你那個 text1.text = a(n) 是什麼意思 我沒有太搞明白 按照要求輸出
一組數的最小值和最大值就是這樣子
你看那兒不明白再問吧
vb取最大值和最小值
5樓:安全管理人
private sub command1_click()dim min%, max%, i%, a(1 to 10) as integer
randomize
for i = 1 to 10
a(i) = int(rnd() * 89) + 10next i
min = a(1): max = a(1)for i = 2 to 10
if a(i) > max then max = a(i)if a(i) < min then min = a(i)next i
text1.text = max
text2.text = min
end sub
6樓:出釹
dim v(n),max_temp,maxprivate sub a()
for i=0 to n
if v(i)>max_temp then max_temp=v(i)
next
max=max_temp
end sub
具體程式要小改下,v(n)要定義下,就是n個數,迴圈比較,發現比臨時變數大的,就把變數給臨時變數,最後得到的就是最大值
7樓:匿名使用者
sub 最值()
dim arrobj as variantarrobj = array(1, 2, 3, 4, 5, 6, 7, 1, 3, 2, 1, 56, 5, 4) '括號內填上你測得的一系列數
dim tempmax as doubledim tempmin as doubletempmax = arrobj(0)
tempmin = arrobj(0)
for i = 0 to ubound(arrobj)if arrobj(i) > tempmax thentempmax = arrobj(i)
end if
if arrobj(i) < tempmin thentempmin = arrobj(i)
end if
next
msgbox "最大值為:" & tempmax & vblf & "最小值為:" & tempmin
end sub
'說明:先假設一個數,這裡比如是陣列中的第一項為最大值,則逐個與其比較,如果大於它,則將它替代悼。最終得到最大值。
vb中求任意六個值中最大值和最小值
8樓:陝西烽火射頻
在函式中可以完成你的要求,我看到的時候比較晚,不還意思,樓上的應該已經給你處理過了
9樓:吾桐語
任意6個值,我就以隨機產生6個兩位正整數為例好了,**如下:
private sub command1_click()dim a(6) as integer
for i = 1 to 6
randomize
a(i) = int(rnd * 90) + 10print a(i);
next i
max = a(1)
min = a(1)
for i = 1 to 6
if max < a(i) then max = a(i)if min > a(i) then min = a(i)next i
print "最大值為:" & max
print "最小值為:" & min
end sub
vb中求最小值問題
10樓:匿名使用者
public function min(byref sztmp()) as variant '求最小值函式
min = sztmp(lbound(sztmp))for j = lbound(sztmp) + 1 to ubound(sztmp)
if min > val(sztmp(j)) then min = val(sztmp(j))
next j
end function
private sub command1_click()dim b0(3)
b0(0) = 11
b0(1) = 12
b0(2) = 10
b0(3) = 1
msgbox min(b0())
end sub
vb中怎麼用函式max和min 求出一組資料的最大值和最小值
11樓:匿名使用者
您好,vb中沒有max和min函式,不過你可以自己程式設計實現。
給你一個求隨機產生6個兩位正整數的例子:
private sub command1_click()dim a(6) as integer
for i = 1 to 6
randomize
a(i) = int(rnd * 90) + 10print a(i);
next i
max = a(1)
min = a(1)
for i = 1 to 6
if max < a(i) then max = a(i)if min > a(i) then min = a(i)next i
print "最大值為:" & max
print "最小值為:" & min
end sub
12樓:匿名使用者
vb自帶的函式中沒有你說的max和min函式。
13樓:匿名使用者
max(a, b) 換成iif(a>b,a,b)就成了
14樓:匿名使用者
b=dmax(a,a)
c=dmin(a,a)
自己錄個巨集看看就明白了
在VB中尋找陣列的最大值或最小值,可否用Max或Min函
vb沒有max和min函式,需要自己編寫 private sub command1 click dim arr 1 to 100 as integerrandomize for i 1 to 100 arr i int rnd 10000 print format arr i if i mod 10...
求最大值或最小值詳細一點謝謝,求函式的最大值和最小值的方法。
x 2 4x 3 x 2 2 1 x 2時有最小值,最小值 1 x 2 2x 2 x 1 2 3 x 1時有最大值,最大值 3 x 2 4x 3 x 2 2 1 x 2 2 0,因此最小值 1 x 2 2x 2 x 1 2 3 x 1 2 0,因此最大值 3 x2 4x 3 x2 4x 4 1 x ...
求函式y xx 的最大值和最小值
當x 1時 函式y x 3 x 1 3 x x 1 4當 1 x 3時 y x 3 x 1 3 x x 1 2x 2 值域 4 y 4 當x 3時 y x 3 x 1 x 3 x 1 4所以y x 3 x 1 的最大值是4,最小值是 4 我們可以用幾何的辦法來解決這個問題,將此函式看成是平面上一個數...