考试题啊,考不出就完蛋了!!
题:目前的世界人口约为60亿,如果以每年1.4%的速度增长,多少年后世界人口可以达到70亿?请用VB程序实现。 非常感谢!!

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim NowP As Integer
        NowP = 60
        Dim i As Long
        i = 1
        Do While NowP < 70
            NowP = 60 * (i + 1.4)
            i = i + 1
        Loop
        Text1.Text = i
        
    End Sub
      

  2.   

    跟写方程式一样的.MsgBox (70 - 60) / (60 * 0.14) & "年"
      

  3.   

    这个是对的
    Private Sub Command1_Click()
        Dim NowP As Integer
        NowP = 60
        Dim i As Long
        i = 0
        Do While NowP < 70
             i = i + 1
            NowP = NowP * (i + 0.014)
          
        Loop
        Text1.Text = i
        
    End Sub
      

  4.   

    晕又错了,这回对了
    Private Sub Command1_Click()
        Dim NowP As Integer
        NowP = 60
        Dim i As Long
        i = 0
        Do While NowP < 70
             i = i + 1
            NowP = NowP * (1 + 0.014)
          
        Loop
        Text1.Text = i
        
    End Sub
      

  5.   

    Private Sub Command1_Click()
        Dim NowP As Double
        NowP = 60
        Dim i As Long
        i = 0
        Do While NowP < 70
             i = i + 1
            NowP = NowP * (1 + 0.014)
          
        Loop
        Text1.Text = i
        
    End Sub
      

  6.   

    好象不对,NowP = 60 * (i + 1.4)中i应该是不变的,为1吧
      

  7.   

    Private Sub Form_click()
    Dim NowP As Single 
        NowP = 60
        Dim i As Long
        i = 0
        Do While NowP < 70
            NowP = NowP * (1 + 0.014)
            i = i + 1
        Loop
          Print  i
    End Sub
    你看这样对吗
      

  8.   

    MsgBox (70 - 60) / (60 * 0.14) & "年"
      

  9.   

    if CInt(Log(70 / 60) / Log(1 + 0.014))<Log(70 / 60) / Log(1 + 0.014) then
      msgbox(CInt(Log(70 / 60) / Log(1 + 0.014))+1)
    else
      msgbox(CInt(Log(70 / 60) / Log(1 + 0.014)))
    end if
    答案就是12年.用这样的算法也可以:
    Private Sub Form_Load()
        Dim NowP As Double '不能定义为integer,会影响精度的
        NowP = 60
        Dim i As Long
        i = 0
        Do While NowP < 70
             i = i + 1
            NowP = (NowP * (1 + 0.014)) 'NowP = (NowP * (i + 0.014)) 是严重错误的!
        Loop
        MsgBox (i & "年")End Sub结果同样是12年.<神行>的算法是错的,只要2年就达到了70亿,这样快地球早人满为患了.