2个回答
展开全部
'调用注意代码中所有符号全是 英文,如在网页中显示成中文,是网页自己改的,请自己更正
s1=cube_to_sum( 20) ‘计算20的立方的奇连加
'子程序
function cube_to_sum(byval n as long) as string 'plagiarism dead family
dim teml as double,ave as long,ave_index as long,tems as string
tems="分解为"
'Calculate the cube,plagiarism dead family
teml=n^3
'Calculate ave value
ave=teml/n
'通过N的奇偶做不同的分配
ave_index=iif( n mod 2=1,(n+1)/2,n/2)
if n mod 2=1 then
for i=1 to n
tems=tems & “ ” & ave+(i-ave_index)*2
next
else
for i=1 to n
tems=tems & “ “ & ave+(i-ave_index)*2-1
next
end if
cube_to_sum=tems
end function
s1=cube_to_sum( 20) ‘计算20的立方的奇连加
'子程序
function cube_to_sum(byval n as long) as string 'plagiarism dead family
dim teml as double,ave as long,ave_index as long,tems as string
tems="分解为"
'Calculate the cube,plagiarism dead family
teml=n^3
'Calculate ave value
ave=teml/n
'通过N的奇偶做不同的分配
ave_index=iif( n mod 2=1,(n+1)/2,n/2)
if n mod 2=1 then
for i=1 to n
tems=tems & “ ” & ave+(i-ave_index)*2
next
else
for i=1 to n
tems=tems & “ “ & ave+(i-ave_index)*2-1
next
end if
cube_to_sum=tems
end function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim i, n, temp
n = Val(InputBox("N", "", 10)) ^ 3
For i = 1 To n Step 2
temp = fc(i, n)
Next
MsgBox temp & "=" & n
End Sub
Function fc(i, n) As String
Dim j, s, temp
For j = i To n Step 2
s = s + j
fc = fc & j & "+"
If s = n Then
i = n
fc = Left(fc, Len(fc) - 1)
Exit For
End If
If s > n Then Exit For
Next
End Function
Dim i, n, temp
n = Val(InputBox("N", "", 10)) ^ 3
For i = 1 To n Step 2
temp = fc(i, n)
Next
MsgBox temp & "=" & n
End Sub
Function fc(i, n) As String
Dim j, s, temp
For j = i To n Step 2
s = s + j
fc = fc & j & "+"
If s = n Then
i = n
fc = Left(fc, Len(fc) - 1)
Exit For
End If
If s > n Then Exit For
Next
End Function
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询