一道VB题目

Dim a As Integer, b As Integer
Private Sub Command1_Click()
Dim c As Integer
a = 3: b = 2: c = 1
Print fun(a, c)
Print a; b; c
Print fun(b, c)
End Sub
Private Function fun(k As Integer, n As Integer) As Single
fun = a + b + k / 2
a = a + b + n
b = a + k
k = b + a
End Function
问第一行,第二行,第三行,分别是多少?
答案是(1)6.5 (2)18 12 1 (3)36
怎么算的啊,我不会,特别是第二行和第三行的输出,怎么来的?谁能帮我详细解答一下啊

Dim a As Integer, b As Integer '全局声明 a,b为数字类型
Private Sub Command1_Click() '按下按钮
Dim c As Integer '过程声明 c为数字类型
a = 3: b = 2: c = 1 '初赋值 a=3 b=2 c=1
Print fun(a, c) '使用Fun函数并输出Fun的值 :此时a=3 c=1
Print a; b; c '输出a ,b ,c 的值 'a=18 b=12 c=1
Print funa(b, c) '使用Funa函数并输出Funa的值
End Sub

Private Function fun(k As Integer, n As Integer) As Single
Rem 这一个函数 函数名(第一个值,第二个值)这个函数的返回类型 k=a=3,n=c=1
fun = a + b + k / 2 'fun=a+b+k/2 其中k=a=3 3+2+1.5=6.5 fun=6.5
a = a + b + n 'a=a+b+n 其中n=c=1 结果 3+2+1=6 a=6 因为a改变k=a=6
b = a + k 'b=a+k 其中k=a=6 结果 6+6=12 b=12
k = b + a 'k=b+a 结果 12+6=18 k=18 因为函数原因 a=k=18
End Function

Rem 因为要区别开来所以我新建另一函数来说明
Private Function funa(k As Integer, n As Integer) As Single
Rem 这一个函数 函数名(第一个值,第二个值)这个函数的返回类型 k=b=12,n=c=1
funa = a + b + k / 2 'funa=a+b+k/2 其中k=b=12 18+12+12/2=36 funa=36
a = a + b + n 'a=a+b+n 其中n=c=1 结果 18+12+1=31 a=31
b = a + k 'b=a+k 其中k=b=12 结果 31+12=43 b=43
k = b + a 'k=b+a 结果 43+31=74 k=74 因为函数原因 b=k=74
End Function

Rem 不明的就HI我
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜