當前位置:編程學習大全網 - 編程軟體 - vb 編程 編寫壹個求2個數中最小值Min的過程,然後用這個過程求4個數的最小值。

vb 編程 編寫壹個求2個數中最小值Min的過程,然後用這個過程求4個數的最小值。

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)

  • 上一篇:位置編程源代碼
  • 下一篇:用C語言編程有哪些比較好的圖形庫?
  • copyright 2024編程學習大全網