二级vb上机题

验证2~10之间的整数的立方都等于一连串连续奇数的和。(改错)OptionExplicitPrivateSubCommand1_Click()DimiAsInteger,... 验证2~10之间的整数的立方都等于一连串连续奇数的和。(改错)
Option Explicit

Private Sub Command1_Click()
Dim i As Integer, st As String
Dim n() As Integer, k As Integer
For i = 2 To 10
call check (i,n)
st = st & CStr(i) & "^3=" & CStr(i ^ 3) & "="
For k = 1 To UBound(n) - 1
st = st & Str(n(k)) & "+"
Next k
st = st & Str(n(k)) & vbCrLf
Next i
text1 = st
End Sub

Private Sub Click(n As Integer, a() As Integer)
Dim sum As Integer, i As Integer, j As Integer
Dim p As Integer
n = m ^ 3
For i = 1 To n \ 2 Step 2
For j = i To n Step 2
p = 0
sum = sum + j
p = p + 1
ReDim Preserve a(p)
a(p) = 1
If sum = n Then Exit For
If sum > n Then Exit For
Next j
Erase a
sum = 0
Next i
End Sub
展开
 我来答
远风的梦想家
2010-07-19 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
Option Explicit

Private Sub Command1_Click()
Dim i As Integer, st As String
Dim n() As Integer, k As Integer
For i = 2 To 10
Call check(i, n)
st = st & CStr(i) & "^3=" & CStr(i ^ 3) & "="
For k = 1 To UBound(n) - 1
st = st & Str(n(k)) & "+"
Next k
st = st & Str(n(k)) & vbCrLf
Next i
Text1 = st
End Sub

Private Sub check(ByVal n As Integer, a() As Integer)'名字错了,并且n是byval的传递方式
Dim sum As Integer, i As Integer, j As Integer
Dim p As Integer
n = n ^ 3'这里是n
For i = 1 To n \ 2 Step 2
p = 0'赋值在外面
For j = i To n Step 2
sum = sum + j
p = p + 1
ReDim Preserve a(p)
a(p) = j'记录的是p的值
If sum = n Then Exit Sub'退出程序
If sum > n Then Exit For
Next j
Erase a
sum = 0
Next i
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式