Private Sub Command1_Click() s = p(1) + p(2) + p(3) + p(4) Print s;Private Sub Command1_Click()s = p(1) + p(2) + p(3) + p(4)Print s;End SubPublic Function p(n As Integer)Static sumFor I = 1 To nsum = sum + INext Ip = sum End Function
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 19:03:41
Private Sub Command1_Click() s = p(1) + p(2) + p(3) + p(4) Print s;Private Sub Command1_Click()s = p(1) + p(2) + p(3) + p(4)Print s;End SubPublic Function p(n As Integer)Static sumFor I = 1 To nsum = sum + INext Ip = sum End Function
Private Sub Command1_Click() s = p(1) + p(2) + p(3) + p(4) Print s;
Private Sub Command1_Click()
s = p(1) + p(2) + p(3) + p(4)
Print s;
End Sub
Public Function p(n As Integer)
Static sum
For I = 1 To n
sum = sum + I
Next I
p = sum
End Function
Private Sub Command1_Click() s = p(1) + p(2) + p(3) + p(4) Print s;Private Sub Command1_Click()s = p(1) + p(2) + p(3) + p(4)Print s;End SubPublic Function p(n As Integer)Static sumFor I = 1 To nsum = sum + INext Ip = sum End Function
static sum 是静态的变量,他不会自动清空.p(1)=0+1=1;p(2)=sum+1+1=3;p(3)=sum+1+1+1=6;t同理p(4)=10;s=1+3+6+10=20.我把vb放下很久了.试着做一下.
答案是:20.