编写程序,已知:S=1+3+5+7+...+99,求S不大于150的最大值 

解决方案 »

  1.   

    哥们,这是一个典型的数学问题,等差数列,压根用不着程序,如一定要用程序,请看如下分析先:
    1、数列的常规项:An=2*n-1
    2、数列的前N项之和:Sn=(1+An)/2*n,也就是:n^2
    3、所以,要求只和不大于150,也就是:n^2<=150
      

  2.   

    当然,如果非要用程序,那就是用循环来做
    dim S as Integer
    S=0
    For n=1 to 1000
       S=S+n
       if S>150 then Exit For
    Next n
    Debug.print "和不大于150的最大值是:" & cstr(n-1)
      

  3.   

    setp 2
      

  4.   

     Dim i As Integer
      Dim s As Integer
      i = 1
      Do While s + i < 150
         s = s + i
         i = i + 2
      Loop
      MsgBox s
      

  5.   

    呵呵,老师考的是 Do While 的编写,不是计算结果。
      

  6.   

    Private Sub Form_Load()
        
        Dim s As Integer
        Do While s <= 150
            temp = s
            s = s + 2
        Loop
        MsgBox "满足条件的s为:" & temp, vbInformation, "结果"
    End Sub
    试试这个