当前位置:编程学习 > VB >>

vb编程题

现在地球人口约为60亿,增长率如果是0.4%,设计一个程序可计算随意的人口数目在几年后超过多少亿。详细点哦。
答案:'添加2个command、2个text控件
'计算已经给你写了,其它的呢自己修改一下
Option Explicit
Const N = 60 '假设现在的人口为60亿,自己修改
Private Sub Command1_Click()
    If Text1.Text <> "" And IsNumeric(Text1.Text) And Text2.Text <> "" And IsNumeric(Text2.Text) Then
        MsgBox (N & "亿人口经过" & Text1.Text & "年后的人口数为:" & N * (1 + 0.004) ^ Val(Text1.Text))
    End If
End Sub
Private Sub Command2_Click()
    If Text2.Text <> "" And IsNumeric(Text2.Text) Then
        MsgBox (N & "亿人口需要经过" & Log(Text2.Text / N) / Log(1 + 0.004) & "年才能达到" & Text2.Text & "亿")
    End If
End Sub
Private Sub Form_Load()
    Command1.Caption = "按年算人口"
    Command2.Caption = "按人口算年"
    Text1.Text = "10"
    Text2.Text = "80"
End Sub

上一个:vb编程解答
下一个:VB编程填空题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,