vb 编程 编写一个求2个数中最大值Max的过程,然后用这个过程求4个数的最大值
1个回答
展开全部
1、冒泡法排序后输出最大值和最小值
dim ss
num=val(inputbox ("输入要求的数的个数"))
dim a(1 to num)
for i=1 to num
a(i)=texti.text
next
for m=num to 2
for n=1 to m-1
if a(n)>=a(n+1) then
ss=a(n+1)
a(n+1)=a(n)
a(n)=ss
end if
next
next
print "MAX:" & a(num)
print "MIN:" & a(1)
2、直接求最大值和最小值
dim ss
num=val(inputbox ("输入要求的数的个数"))
dim a(1 to num)
for i=1 to num
a(i)=texti.text
next
for i=1 to num-1
if a(i)>=a(i+1) then
ss=a(i+1)
a(i+1)=a(i)
a(i)=ss
end if
next
print "MIN:" & a(1)
for i=1 to num-1
if a(i)<=a(i+1) then
ss=a(i+1)
a(i+1)=a(i)
a(i)=ss
end if
next
print "MAX:" & a(1)
dim ss
num=val(inputbox ("输入要求的数的个数"))
dim a(1 to num)
for i=1 to num
a(i)=texti.text
next
for m=num to 2
for n=1 to m-1
if a(n)>=a(n+1) then
ss=a(n+1)
a(n+1)=a(n)
a(n)=ss
end if
next
next
print "MAX:" & a(num)
print "MIN:" & a(1)
2、直接求最大值和最小值
dim ss
num=val(inputbox ("输入要求的数的个数"))
dim a(1 to num)
for i=1 to num
a(i)=texti.text
next
for i=1 to num-1
if a(i)>=a(i+1) then
ss=a(i+1)
a(i+1)=a(i)
a(i)=ss
end if
next
print "MIN:" & a(1)
for i=1 to num-1
if a(i)<=a(i+1) then
ss=a(i+1)
a(i+1)=a(i)
a(i)=ss
end if
next
print "MAX:" & a(1)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询