文档介绍:程序设计题
1.
编程,输入X值,按下式计算并输出y值。 _ 、
y — j(尤)
x + 3
X 2 y/~X 0
Private Sub Form_Click()
Dim x As Single, y As Single
x = lnputBox("请输入 x 的值:“)
If x > 3 Then
y = x + 3
Elself x >= 1 Then
y = x * x
Elself x>0Then
y = Sqr(x)
Else
y = 0
End If
Print y
End Sub
2.
计算下式的和,
变量x与〃的数值用输入对话框输入。
x3
xn
x x2 .. ..
s — — + + + ... +
2! 3! 4! (〃 + 1)!
Private Sub Form_Click()
Dim x As Single, s As Single, t As Single
Dim i As Integer, n As Integer
x = lnputBox("请输入 x 的值:“)
n = lnputBox("请输入 n 的值:")
t = x/2:s = t
For i = 3 To n
t = t * x/i
s = s +1
Next i
Print s
End Sub
用近似公式求自然对数的底数e的值,直到前后两项之差小于10“为止。
, 1 1 1 1
e « 1 + ——+ ——+ ——+ ... + —— 1! 2! 3! n!
Private Sub Form_Click()
Dim e As Single, t As Single, i As Integer
e = 2: t = 1: i = 1
While t>=
i = i + 1: t = t/i:e = e + t
Wend
Print e
End Sub
编制通用函数过程,计算Double类型一维数组所有元素的平均值。
Private Function fsum(x() As Double, n As Integer) As Double
Dim i As Integer
For i = 1 To n
fsum = fsum + x(i)
Next i
fsum = fsum / n
End Function
编程,运行时界面如图10-4所示,选中不同单选按钮时在文本框中显示不同的内容。
Private Sub Form_Load()
="当前 日期: = Date
Optionl(O).Caption = ”显示日期”:Optionl(l).Caption ="显示时间”
Optionl(0).Value = True: = ”退出”
End Sub
Private Sub Optionl_Click(lndex As Integer)
Select Case Index
Case 0
= ”当前日期:Text = Date
Case 1
Labe