VB代码 求三个数中的最大数和最小数

来源:百度知道 编辑:UC知道 时间:2024/06/22 23:44:47
VB代码 求三个数中的最大数和最小数

假设 三个数字为 a,b,c,你设置个text输入自己想要比较的数字
dim a as integer, b as integer,c as integer,i as integer
dim a() as integer
a=text1:b=text2:c=text3
redim a(3)
a(1)=a:a(2)=b:a(3)=c
for i=1 to 2
for j= i+1 to 3
if a(i)<a(j) then
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
next j
next i
上面这段代码是选择出最大数字的

dim a as integer, b as integer,c as integer,i as integer
dim a() as integer
a=text1:b=text2:c=text3
redim a(3)
a(1)=a:a(2)=b:a(3)=c
for i=1 to 2
for j= i+1 to 3
if a(i)》a(j) then
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
next j
next i

这个代码是选择出最小数字的。

比较方法还有很多,比如,直接排序法,冒泡排序法,等等。看你需要什么了,
上面的方法是比较排序法,是最基础的,你因该能看的明白~祝你VB学习一路顺风!!!!!

修正一下:
amax=a(1)
amin=a(2)
n=3
For i=1 to n
if amax<a(i) then amax=a(i)
if amin>a(i) then amin=a(i)
next

Private Sub Command1_Click()
If