vb编程:求a=1+3+5+.+(2n-1)的值Private Sub Form_click()Dim a As IntegerDim i As IntegerDim n As Integern = InputBox("n=")For i = 1 To n a = a + 2 * n - 1Next iPrint "n="; n, "a="; aEnd Sub怎么不对呢?

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 05:59:44

vb编程:求a=1+3+5+.+(2n-1)的值Private Sub Form_click()Dim a As IntegerDim i As IntegerDim n As Integern = InputBox("n=")For i = 1 To n a = a + 2 * n - 1Next iPrint "n="; n, "a="; aEnd Sub怎么不对呢?
vb编程:求a=1+3+5+.+(2n-1)的值
Private Sub Form_click()
Dim a As Integer
Dim i As Integer
Dim n As Integer
n = InputBox("n=")
For i = 1 To n
a = a + 2 * n - 1
Next i
Print "n="; n, "a="; a
End Sub
怎么不对呢?

vb编程:求a=1+3+5+.+(2n-1)的值Private Sub Form_click()Dim a As IntegerDim i As IntegerDim n As Integern = InputBox("n=")For i = 1 To n a = a + 2 * n - 1Next iPrint "n="; n, "a="; aEnd Sub怎么不对呢?
for 循环修改下
for i=1 to 2n-1 step 2
a=a+i
next i