作业帮 > 综合 > 作业

VB,求详细解答过程求N A B答案是10 27 9不知怎么的出来的,别让我自己按F8,考试不可能把计算机带过去

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/06/03 13:30:51
VB,求详细解答过程求N A B答案是10 27 9不知怎么的出来的,别让我自己按F8,考试不可能把计算机带过去
option explict dim n as integer private sub command1_click() dim a as integer,b as integer a=2b=3 for n=1 to 6 if n mod 2=0 then b=fun(n,a)+a else a=fun(b,n)+b end if next n print n,a,b end sub private function fun(x as integer,y as integer)as integer x=y-1+n y=x+y-n fun=x+y end function
Dim n As Integer
Private Sub command1_click()
Dim a As Integer, b As Integer
a = 2
b = 3
For n = 1 To 6
If n Mod 2 = 0 Then '当 n为 2 4 6
n = a - 1 + n
b = n + a * 2
Else ' 1 3
b = 2 * n - 1
n = b
a = 2 * b + n
End If
Next n
Print n, a, b
End Sub
额 什么怎么来的?
再问: If n Mod 2 = 0 Then '当 n为 2 4 6 n = a - 1 + n b = n + a * 2 这个b的表达式怎么得到的,没看到有*这个符号啊
再答: 你把函数分开来啊,函数就是为了少写些代码
再问: 帮帮忙啊,详细点把。