编写函数fun,函数的功能是:当x的初值为10,'每年增长率为百分之一,计算多少年以后x的值能达到y,'并显示所需年数的值(变量名必须为n).'要求使用Do ...Loop Until语句来实现.

来源:学生作业学帮网 编辑:学帮网 时间:2024/06/01 04:36:34

编写函数fun,函数的功能是:当x的初值为10,
'每年增长率为百分之一,计算多少年以后x的值能达到y,
'并显示所需年数的值(变量名必须为n).
'要求使用Do ...Loop Until语句来实现.

Private Sub Command1_Click()
    Dim x As Single, y As Single
    x = 10
    y = 1000
    MsgBox fun(x, y)
End Sub

Function fun(x As Single, y As Single) As Long
    Do
        x = x * 1.01
        c = c + 1
    Loop Until x >= y
    fun = c
End Function