VB编程,编写计算fun(N)=1×2+2×3+3×4+...+n×(n+1)的运算,n为任意整数
1个回答
展开全部
'窗体上加一个命令按钮即可。供参考。祝进步。朋友。
Private Sub Command1_Click()
Dim n As Integer
n = InputBox("请输入一个正整数")
Print "fun(N)=1*2+2*3+3*4+...+n*(n+1)结果为:"; myfun(n)
End Sub
Private Function myfun(ByVal n As Integer) As Long
Dim m As Long
For i = 1 To n
m = m + i * (i + 1)
Next i
myfun = m
End Function
Private Sub Command1_Click()
Dim n As Integer
n = InputBox("请输入一个正整数")
Print "fun(N)=1*2+2*3+3*4+...+n*(n+1)结果为:"; myfun(n)
End Sub
Private Function myfun(ByVal n As Integer) As Long
Dim m As Long
For i = 1 To n
m = m + i * (i + 1)
Next i
myfun = m
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询