二级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 展开
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 展开
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询