求一道VB题的解答
PrivateSubCommand1_Click()DimxAsInteger,yAsIntegerDimnAsInteger,zAsIntegerx=1:y=1Forn...
Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Next n
Print n, z
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
为什么这道题的答案是1 6 2 11 3 16
帮忙分析一下 展开
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Next n
Print n, z
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
为什么这道题的答案是1 6 2 11 3 16
帮忙分析一下 展开
4个回答
展开全部
Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Next n
Print n, z
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
为什么这道题的答案是1 6 2 11 3 16
你给的答案和程序对不上的,Print n, z应该放在for循环里面
Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
//当N=1时,x=1,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=6 y=1
//当N=2时,x=6,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=11 y=1
//当N=3时,x=11,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=16 y=1
//x和y的值在调用函数之后,在调用函数里被改变了
Print n, z
Next n
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer //因为n是局部变量,所以每次调用时n的初始值为0开始
//这里的n和上面的n不通用
//x y 函数变量传递,x 和 y值的改变会影响传递变量的值,现在这个程序的y值始终不变,也就相当于x=x+5
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Next n
Print n, z
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
为什么这道题的答案是1 6 2 11 3 16
你给的答案和程序对不上的,Print n, z应该放在for循环里面
Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
//当N=1时,x=1,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=6 y=1
//当N=2时,x=6,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=11 y=1
//当N=3时,x=11,y=1 调用函数fistfunc :该函数n=0开始到n《=4 执行了五次循环 得到x=16 y=1
//x和y的值在调用函数之后,在调用函数里被改变了
Print n, z
Next n
End Sub
Private Function fistfunc(x As Integer, y As Integer)
Dim n As Integer //因为n是局部变量,所以每次调用时n的初始值为0开始
//这里的n和上面的n不通用
//x y 函数变量传递,x 和 y值的改变会影响传递变量的值,现在这个程序的y值始终不变,也就相当于x=x+5
Do While n <= 4
x = x + y
n = n + 1
Loop
fistfunc = x
End Function
展开全部
代码你写错了。应该是:
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Print n, z
Next n
这样才能得出答案,应该明白了吧
x = 1: y = 1
For n = 1 To 3
z = fistfunc(x, y)
Print n, z
Next n
这样才能得出答案,应该明白了吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这个程序,得出来得答案是4 16
因为 Print n, z 写在循环外面了,所以只执行一次
n=1 to 3 执行完循环后 next n
所以n=4
那个function里面
x=1+1 x=2+1 x=3+1 x=4+1 x=5+1
x=6+1 x=7+1 ...
...
所以z=16
至于你想要得到得那个答案,请参见楼上。
因为 Print n, z 写在循环外面了,所以只执行一次
n=1 to 3 执行完循环后 next n
所以n=4
那个function里面
x=1+1 x=2+1 x=3+1 x=4+1 x=5+1
x=6+1 x=7+1 ...
...
所以z=16
至于你想要得到得那个答案,请参见楼上。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询