【发布时间】:2017-10-18 19:25:16
【问题描述】:
我正在使用 VBscript。
所以正如标题所说,我需要输入一组数字,我必须输出其中最大的,最小的和平均值。
我不知道如何做平均值,但是我做了最大和最小但出现了错误(“堆栈空间不足”“最大”第 6 行)
(抱歉格式不知道怎么编辑)
function Largest(a)
maxi = -99999
if a>maxi then
maxi=a
end if
msgbox Largest(a)
end function
function Smallest(a)
maxi = +99999
if a<maxi then
maxi=a
end if
msgbox Smallest(a)
end function
n = inputbox("Enter the numbers of items")
for i = 1 to n
a = CInt(InputBox("Enter Item " &i))
Largest(a)
Smallest(a)
next
我想出了如何计算平均值,但不知道如何将其合并到上面的代码中:
n=inputbox("Enter number of items")
sum = 0
for i = 1 to n
a = inputbox("enter items "&i)
sum = sum + a
next
avg = sum/n
msgbox avg
【问题讨论】:
-
I'm using VBscript那么你使用了错误的标签。 VB.NET 之于 VBScript 就像 Car 之于 Carpet。请阅读How to Ask 并采取tour -
我从未做过任何 vb 脚本,但求平均值就像将所有元素相加并除以数组的计数一样简单。
标签: loops for-loop if-statement vbscript