编写一个vb函数,其功能是求∑n,并调用.

如题所述

被系统提示来帮忙解决这个问题
很久没用VB了,语法有点陌生了
这个函数很容易的
你也可以用数学方法
如下:
PRIVATE SUB EN(N AS LONG) AS LONG
EN=(N+1)*N/2
END SUB
就这么简单
数学公式哈
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-14
private function Sum(N as long) as long
dim i as long
for i=1 to n
sum=sum+i
next i
end sub
第2个回答  2011-04-14
'借鉴了anankid的
Private Function Sum(N as long) as Long
Dim i As Long
For i=1 To n
Sum=Sum+i
Next i
End Function

Private Sub Command1_Click()
Msgbox Sum(100)'求1到100的和
End Sub
第3个回答  2011-04-14
Option Explicit

Private Sub Form_Click()
Dim n As Integer, s As Integer, i As Integer
n = 100
For i = 1 To n
s = s + i
Next
Print s
End Sub
相似回答
大家正在搜