早教吧 育儿知识 作业答案 考试题库 百科 知识分享

VB,求详细解答过程求NAB答案是10279不知怎么的出来的,别让我自己按F8,考试不可能把计算机带过去optionexplictdimnasintegerprivatesubcommand1click()dimaasinteger,basintegera=2b=3forn=1to6ifnmod

题目详情
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
额 什么怎么来的?