下面程序的功能是
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
下面程序的功能是:计算f=1-1/(2*3)+1/(3*4)-1/(4*5)+……+1/(19*20)
Private Sub Form_Click()
Dim f,i,sign As Integer
____ sign=1________
f = 1
______ for i=2 to 19_______
f = f + sign / (i * (i + 1))
________ sign=-1*sign_________
Next i
Print “f=”;f
End Sub
11.下面的程序是在一个字符串变量中查找“at”,并用消息框给出查找结果的报告:没有找到或找到的个数,程序如下:
Public Sub Findat()
Dim Str1 As String
Dim length As Integer
Dim sum As Integer
Dim i As Integer
Str1 = InputBox (“请输入一个字符串”)
length = _______ len(Str1)_________
i = 1
sum = 0
Do While i <= _______ Length _________
If _______ mid(Str1,i,2)_______ = “at” Then
sum = sum + 1
End If
i = i + 1
Loop
If _______ sum=0_______ Then
MsgBox “没有找到!”
Else
MsgBox “找到了” & Str (sum) & “个”
End If
End Sub
下面程序的功能是:单击窗体后,输入英文句子,将其每个单词首字母变为大字字母,再输出
Private Sub Form_Click()
Dim oldsen As String, newsen As String
Dim char As String, lastchar As String
Dim n As Integer, i As Integer
oldsen = InputBox("请输入英文句子:")
n = Len(oldsen)
lastchar = " "
For i = 1 To n
char = Mid(oldsen, i, 1)
If lastchar = " " Then
char = UCase(char) '变为大写
End If
newsen = newsen & char
lastchar = char Next i
Print "input:" ;oldsen
Print "output:" ;newsen
End Sub
编写程序,使用InputBox函数输入两个电阻的值,求它们并联和串联的电阻值,使用MsgBox 消息框输出结果,要要求保留三位小数
Sub Macro2()
Dim s1, s2 As String
Dim n5
Dim n1, n2, n3, n4 As Single
s1 = InputBox("请输入两电阻的阻值,之间用半角逗号“,”分隔", "提示信息")
n1 = Val(s1)
n2 = Val(Mid(s1, InStr(s1, ",") + 1))
If n1 > 0 And n2 > 0 Then
n3 = Round(n1 + n2, 3) '串联电阻值
n4 = Round(n1 * n2 / (n1 + n2), 3) '并联电阻值
n5 = MsgBox(n1 & "Ω和" & n2 & "Ω两个电阻的" & Chr(13) & "串联电阻值为:" & n3 & "Ω" & Chr(13) & "并联电阻值为:" & n4 & "Ω", , "计算结果")
Else
n5 = MsgBox("两电阻值输入有错,请重新输入!", , "错误提示")
End If
End Sub
用inputbox函数输入3个数据,如果这3个数据能构成三角形,计算并在窗体上输出三角形面积。
Private Sub Command1_Click()
Dim a, b, c, s, x
a = Val(InputBox("请输入第一条边长"))
b = Val(InputBox("请输入第二条边长"))
c = Val(InputBox("请输入第三条边长"))
If a + b > c And a + c > b And b + c > a Then
Print "能组成三角形"
x = 1 / 2 * (a + b + c)
s = Sqr(x * (x - a) * (x - b) * (x - c))
Print "三角形面积s="; s
Else
Print "不能组成三角形"
End If
End Sub
编程计算下列分段函数值
f(x)=1.x2+x-6 x<0且x不等于3
2.x2-5x+6 0<=x<10且x不等于2和3
3.x2-x-1 其他
if x<0 then
f=x^2+x-6
elseif x<10 and x>=0 and x<>2 and x<>3 then
f=x^2-5*x+6
else
f=x^2-x-1
end if
Function jc(n As Integer) As Long
编写程序计算1+2!+3!+4!+……+10!的程序
Private Sub Form_Click()
Dim s As Double
m = 1
For n = 1 To 10
m = m * n
s = s + m
Next
Print s
End Sub