改错
[(第1题》『程序改错」(5分)(题号:132)
【程序改错】
'题目:求s二2!+4X6!+8!,阶乘的计算用Function过程
'fact实现
'注意:不可增加或删除程序行,也不可以更改程序结构
j
Private Sub Form_Click()
dim i as integer,s as Long
'**********F0UND**********
For i = 2 To 8
s = s + fact (i)
Next i
Print s
End Sub
'**********F0UND**********
Public Function fact()
dim t as Long
dim i as integer
t = 1
For i = 1 To n
t = t * i
Next I
'**********F0UND**********
fact=i
End Function
答案:
1)
fact(n As 或 Public
. For i = 2 To 8 Step 22). Public Function fact(ByVai n As Integer) 或 Public Function Integer) 或 Public Function fact(n%) 或 Public Function fact(n) Function fact(ByVai n%) 或 Public Function fact(ByVai n)
3). fact = t
K第1题》『程序改错」(5分)(题号:132)
【程序改错】
'题目:求s二2!+4!+6!+8!,阶乘的计算用Function 11程 'fact实现
'注意:不可增加或删除程序行,也不可以更改程序结构
Private Sub Form_Click()
dim i as integer, s as Long
'**********F0UND**********
For i = 2 To 8
s = s + fact (i)
Next i
Print s
End Sub
':fc*********F0UND**********
Public Function fact()
dim t as Long
dim i as integer
t = 1
For i = 1 To n
t = t * i
Next I
'**********F0UND**********
fact=i
End Function
答案:
1). For i = 2 To 8 Step 2
2). Public Function fact(ByVai n As Integer) 或 Public Function fact(n As Integer) 或 Public Function fact(n%) 或 Public Function fact(n) 或 Public Function fact(ByVai n%) 或 Public Function fact(ByVai n)
3). fact = t
K第1题》『程序改错」(5分)(题号:493)
【程序改错】
'题目:给左年号与月份,判断该年是否闰年,并根据给出的 '月份来判断是什么季节和该月有多少天
'(闰年的条件是:年号能被4整除但不能被100整除,
'或者能被vb编程基础知识题库400整除°) '注意:不可增加或删除程序行,也不可以更改程序结构
Private Sub Form_Click()
Dim Year As Integer, Month As Integer
Year = InputBox(/z输入年号:")
Month = InputBox(/z输入月份:“)
'**********F0UND**********
If Year Mod 4 = 0 And Year Mod 100 <> 0 And Year Mod 400 <> 0 Then
'**********foUND**********
flag = 0
MsgBox "闰年"
Else
flag = 0
MsgBox "非闰年"
End If
'**********foUND**********
Select Case flag
Case 1
MsgBox "该月有31天,春季"
Case 2
If flag 二 1 Then MsgBox "该月有 29 天,春季"Else MsgBox 〃该月有 28 天,春季"
Case 3
MsgBox "该月有31天,春季"
Case 4
MsgBox "该月有30天,夏季"
Case 5
MsgBox "该月有31天,夏季"
Case 6
MsgBox "该月有30天,夏季"
Case 7
MsgBox该月有31天,秋季"
Case 8
MsgBox "该月有31天,秋季"
Case 9
MsgBox "该月有30天,秋季"
Case 10
MsgBox "该月有31天,冬季"
Case 11
MsgBox "该月有30天,冬季"
Case 12
MsgBox该月有31天,冬季"
End Select
End Sub
答案:
1) . If Year Mod 4 = 0 And Year Mod 100 <> 0 Or Year Mod 400 = 0 Then 或 If Year
Mod 400 = 0 Or Year Mod 4 = 0 And Year Mod 100 <> 0 Then
2) . Flag = 1
3) . Select Case Month
K第2题』『程序改错」(5分)(题号:119)
【程序改错】
'题目:在下面的程序段中过程pd可以判断任意三个数能
'否构成三角形的三边,利用该过程的判泄结果,
'对能构成三角形的讣算其而积,构不成的显示"
'不能构成三角形〃 '注意:不可增加或删除程序行,也不可以更改程序结构
Option Explicit
Private Sub Form_Click()
':fc*********FOUND**********
Dim x%, y%, z%, s%, b As Boolean, h As Single
X = InputBox C请输入三角形的边长")
y = InputBox C请输入三角形的边长")
z = InputBox C请输入三角形的边长")
b = pd(x, y, z)
h = (x + y + z) / 2
'客*********FOUND**********
If Not b Then
s = Sqr (h * (h - x) * (h - y) * (h - z))
Print "三角形而积是";s
Else
Print "不能构成三角形"
End If
End Sub
'**********FOUND**********
Public Function pd() As Boolean
If x > 0 And y > 0 And z > 0 And x + y > z And x + z > y And y + z > x Then pd = True
Else
pd = False
End If
End Function
答案:
1). Dim ★矗★, z%*, ! ★, As Boolean^, ★h As Single 或
Dim ★x%^, ★ z%*, as Singled, As Boolean*, As Single
2). If b Then 或 If b=true Then
3). Public Function pd(x%, y%, z%) As Boolean 或 Public Function pd(x, y, z) As Boolean 或 Public Function pd(x as Integer, y as Integer, z as Integer) As Boolean
K第3题]]『程序改错」(5分)(题号:134)
【程序改错】
'题目:程序功能根拯输入的学习成绩,分别显示优秀 '(90分以上),良好(75分以上),及
格(60分以上) ',不及格几个等级.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论