看一下我的简单的ASP函数,哪里有错

来源:百度知道 编辑:UC知道 时间:2024/05/18 08:00:02
<html><head></head><body>
<script language="vbscript">
dim sum,a(i),i
sum=0,a(0)=1

for i=1 to 10
a(i)=a(i-1)*i
sum=sum+a(i)
next
document.write "1!+2!+........+10!="
</script>

</body></html>
要求输出1到10的阶乘

你的程序有两个地方有误:
(1)dim sum,a(i),i '这句有误, 在a(i)之前, i还未定义.
(2)sum=0,a(0)=1 '应该把逗号去掉,并写成两行. 或者把逗号换成冒号写在一行

<html><head></head><body>
<script language="vbscript">
dim sum,a(10),i
sum=0
a(0)=1

for i=1 to 10
a(i)=a(i-1)*i
sum=sum+a(i)
next
document.write "1!+2!+........+10!=" & sum
</script>

</body></html>

数组里好像不能用表达式吧,也就是:a(i-1) 这写法错了

我现在网吧里, 没IIS测试,我明天回去后再帮你看看~