VBS脚本算法设计题

来源:百度知道 编辑:UC知道 时间:2024/07/02 11:54:55
题目要求:设计一个VBS脚本,用来计算1+2+3+......+100亿的结果,要求最终的结果准确,且计算时间尽可能的少。

用什么方法能准确的算出这个庞大的数字呢?
结果是50000000005000000000,怎么用代码表示出来!

'(首项+末项)*项数/2
WSH.Echo ShowNum((1+100*10^8)*100*10^8/2)

Function ShowNum(ByVal n)
Dim s, a1, a2, sResult
s = CStr(n)
a1 = Split(s, "E+")
a2 = Split(a1(0), ".")
sResult = a2(0) & a2(1) & Space(CInt(a1(1) - Len(a2(1))))
ShowNum = Replace(sResult, " ", 0)
End Function

高斯求和