( ?。?/div>
'讀取n個(gè)數(shù)據(jù),并存儲(chǔ)到數(shù)組a中(代碼略)
EndSub
PrivateSubCommand1_Click ( )
DimiAsInteger,jAsInteger,kAsInteger,spaceAsInteger
Fori=1Ton
c(i)=a(i)
Nexti
k=2'當(dāng)前層第一個(gè)偶數(shù)項(xiàng)的位置
space=1'當(dāng)前層偶數(shù)項(xiàng)與前一項(xiàng)的間距
DoWhilek<=n
Fori=kTonStepk
c(i)=c(i)+c(i-space)
Nexti
k=k*2
①
space=space*2
space=space*2
Loop
EndSub
PrivateSubCommand2_Click ( )
DimxAsInteger,sumAsLong
x=Val(Text1.Text):sum=0
DoWhilex<>0
sum=sum+c(x)
②
x=x-lowbit(x)
x=x-lowbit(x)
Loop
Text2.Text=Str(sum)
EndSub
Functionlowbit(xAsInteger)AsInteger
DimtempAsInteger
temp=x:lowbit=1
DoWhile③
temp Mod2=0
temp Mod2=0
'
lowbit=lowbit*2
temp=temp\2
Loop
EndFunction