长安cs35论坛:帮我看看这个程序哪里错误了

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 00:19:27
X和Y是两个很大的正整数(最多可达一千位),如何求出它们相乘的积?

dim x(1000) as byte,y(1000) as byte,z(2000) as byte
dim d1,d2 as string
sub cheng(a()as byte,b()as byte,c()as byte,n as integer)
for i=1 to 2000:c(i)=0:next i
if n>1 then
dim n1 as integer,n2 as integer
n1=(n+1)\2:n2=n1+n1
dim a1(1000) as byte,b1(1000) as byte,c1(2000) as byte
dim a2(1000) as byte,b2(1000) as byte,c2(2000) as byte
for i=1 to n1
b1(i)=a(i):b2(i)=b(i)
a1(i)=a(n1+i):a2(i)=b(n1+i)
next i
t=0:
call cheng(a1,a2,c2,n1): call cheng(b1,b2,c1,n1)
for i=1 to n2
c(i)=c1(i):c(i+n2)=c2(i)
next i
call cheng(a1,b2,c1,n1): call cheng(b1,a2,c2,n1)
t=0
for i=1 to n2
d=c1(i)+c2(i)+c(i+n1)+t
c(i+n1)=d mod 10
t=d\10
next i
if t>0 then c(n1+n2+1)=c(n1+n2+1)+t
else
d=a(1)*b(1)
c(1)=d mod 10
c(2)=d\10
end if
end sub
private sub command1_click()
dim d1,d2 as string
dim n as integer
d1=text1.text
d2=text2.text
text1.text=""
text2.text=""
for i=1 to len(d1):x(i)=val(left(right(d1,i),1)):next i
for i=1 to len(d2):y(i)=val(left(right(d2,i),1)):next i
n=len(d1): if n<len(d2) then n=len(d2)
call cheng(x,y,z,n)
i=2000
do while z(i)=0 and i>1
i=i-1
loop
text3.text=d1 & "x" & d2 & "="
for j=i to 1 step-1
text3.text=text3.text & ltrim(str(z(j)))
next j
end

把最后的end改成end sub就可以了
其他没发现有什么错
程序可以再优化一下