【加试题】尼克斯彻定理:任何一个大于等于1 的整数的立方等于一串连续奇数之和,如:13=1,23=3+5=8,33=7+9=11。编写一个VB程序验证尼克斯彻定理,程序运行时,在文本框Text1 中输入一个大于等于1的整数,单击“验证”按钮 Command1,在文本框 Text2中显示验证结果,运行界面如图所示。
实现上述功能的VB 代码如下,其中加框处代码有错,请改正。
Dim n As Integer, i As Integer, t As Integer, sum As Long, s As String n = Val(Text1.Text)
For i = 1 To n ^ 3 Step 2
sum = 0: t = i: flag = False
Do While sum <= n ^ 3 And flag = False
sum = sum + t
⑴
If sum = n ^ 3 Then flag = True
Loop
If flag = True Then Exit For
Next i
s = Str(n) + "^" + Str(3) + "="
Do While sum > 0
⑵
If sum = 0 Then
s = s + Str(i)
Else
s = s + Str(i) + "+"
End If
i = i + 2
Loop
Text2.Text = s
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#}