VB改错

  • 格式:doc
  • 大小:77.50 KB
  • 文档页数:6

下载文档原格式

  / 6
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第1题】'题目:已知C的公式表示如下:

' n!

' C=------------------

' (n-m)!*m!

'函数过程fac( )求k!函数,在Fomr_Click事件中完成运算,'请修正程序中错误。

'------------------------------------------------

Option Explicit

Private Function fac(k As Integer) As Single

Dim x As Single, j As Integer

'**********FOUND********** x = 0

For j = 1 To k

'**********FOUND**********

x = x ^ j

Next j

fac = x

End Function

Private Sub Form_Click()

Dim C As Single

Dim m As Integer, n As Integer

m = Val(InputBox("请输入一个整数(m):"))

n = Val(InputBox("请输入一个整数(n):"))

'**********FOUND**********

C = fac(n) / fac(n - m) * fac(m)

Print "C="; C

End Sub 答案:1). x=1 2). x=x*j 或x=j*x

3). C = fac(n) / fac(n - m) / fac(m) 或C = fac(n) / (fac(n - m) * fac(m)) 或C = fac(n) / ( fac(n - m) * fac(m) )

第1题(10.0分)题号:132'【程序改错】

'题目:求s=2!+4!+6!+8!,阶乘

的计算用Function过程

' fact实现

'----------------------------------------

--------

Option Explicit

Private Sub Form_Click()

Dim i As Integer, s As Long

'**********FOUND**********

For i = 2 To 8

s = s + fact(i)

Next i

Print s

End Sub

'**********FOUND**********

Public Function fact()

Dim t As Long

Dim i As Integer

t = 1

For i = 1 To n

t = t * i

Next i

'**********FOUND**********

fact = i

End Function答案:1). For i =

2 To 8 Step 2

2). Public Function fact(ByVal

n As Integer)

3). fact = t

第2 '题目:编程求一个十进制整

数n的各位数字之和,设n为小

于或等于5位的数。

'----------------------------------------

--------

Option Explicit

Private Sub Form_Click()

Dim N As Integer, Sum As

Integer, S1 As String, S2 As

String

Dim i As Integer, Ch As

String

Sum = 0

N = InputBox("输入整数n")

S1 = Str(N)

'**********FOUND**********

S1 = RTrim(S1)

For i = 1 To Len(S1)

'**********FOUND**********

Ch = Mid(N, i, 1)

'**********FOUND**********

Sum = Val(Ch)

Next i

Print "该整数的各位数之和

是:"; Sum

End Sub 答案:1).

S1 = Trim(S1) 或S1 = lTrim(S1)

2). Ch = Mid(S1, i, 1)

3). Sum = Sum + Val(Ch) 或

Sum = Sum + Val(Ch)

━━━━━━━━━━━━━

━━━

第1题(10.0分)题号:458'

【程序改错】

'题目:已知自然对数的底数e的

级数表示如下:

'

e=1+1/1!+1/2!+1/3!+......+1/n!+...

..

' 本程序利用函数过程fact()

求e,其中绝对值小于

' 1E-8的项被忽略。

'----------------------------------------

--------

Option Explicit

Private Function fact(m As

Integer) As Single

Dim x As Single, i As Integer

x = 1

For i = 1 To m

'**********FOUND**********

x = i

Next i

fact = x

End Function

Private Sub Form_Click()

Dim e As Single, item As