求100以内奇数之和,但总是不行
private sub form_load()
  show
 dim i,x As Integer
 for i=1 to 100 step 2    '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
   x=x+i
   print i,x
 next i
end sub

解决方案 »

  1.   

    for i=1 to 100 step 1   '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
       if i mod 2 then
          x=x+i
          print i,x
        end if
     next i
      

  2.   

    for i=1 to 100 step 1   '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
       if i mod 2 then
          x=x+i
          print i,x
        end if
     next i
      

  3.   

    for i=1 to 100 step 1   '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
       if i mod 2 then
          x=x+i
          print i,x
        end if
     next i
      

  4.   

    Private Sub form_load()
      Show
     Dim sum,x, BottomX, TopX As Integer
     BottomX = 0'定义下限
     TopX = 100'定义上限
     x = BottomX'初始变量
     Sum = 0
     While x <= TopX And x >= BottomX
        If x Mod 2 = 1 Then '判断满足条件
            Sum = Sum + x
            Debug.Print x, Sum
        End If
        x = x + 1 '计数加一
    WendEnd Sub
      

  5.   

    奇数原理:从1、3、5----数起,第n项是2n-1总和:
       (1+2n-1)*n/2 = n^2。
      

  6.   

    改为:(1+2n-1)*n/2 = (n^2)/2。