vb 最接近的数有一组数值10002000300040005000600070008000900010000120001400016000180002000030000400005000060000700008000090000100000我想找出最接近2500的数值,怎么弄啊,
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/11 07:30:23
vb 最接近的数有一组数值10002000300040005000600070008000900010000120001400016000180002000030000400005000060000700008000090000100000我想找出最接近2500的数值,怎么弄啊,
vb 最接近的数
有一组数值
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
12000
14000
16000
18000
20000
30000
40000
50000
60000
70000
80000
90000
100000
我想找出最接近2500的数值,怎么弄啊,
vb 最接近的数有一组数值10002000300040005000600070008000900010000120001400016000180002000030000400005000060000700008000090000100000我想找出最接近2500的数值,怎么弄啊,
Sub tt()
Dim mStr$,mArr,i%,k%,Rslt&
mStr = "1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 12000 14000 16000 18000 20000 30000 40000 50000 60000 70000 80000 90000 100000"
mArr = Split(mStr," ")
k = 2500
Rslt = mArr(0) - k
For i = 1 To UBound(mArr)
If Abs(mArr(i) - k) < Abs(Rslt) Then Rslt = mArr(i) - k
Next
MsgBox "最接近的数就是:" & Rslt + k
End Sub