湖南vb程序设计二级计算机考试题库答案,湖南省计算机二级考试VB程序设计题.doc...

湖南省计算机二级考试VB程序设计题

3.程序设计题(35’)

(1)程序改错(15’)

程序功能:求s=1+3+5+7+...直到s>2000为止。程序中有两行有错误。改正错误,使它能输出正确的结果。 2025)

Private Sub Form_Click()

Dim i As Integer, s As Long

s = 0 : i = 1

Do Until s < 2000

s = s + i

i = i + 1

Loop

Print s

End Sub

答案:s>2000 ; i+2

程序功能:计算s=2!+4!+8!。程序中有两行有错误。改正错误,使它能输出正确的结果。 40346)

Private Sub Command1_Click()

Dim k As Integer, i As Integer

Dim s As Long, t As Long

s = 0

i = 1

Do While i <= 3

t = 1

k = 1

While k <= 2*i

t = t * k

k = k + 1

Wend

s = s + t

i = i + 1

wend

Print s

End Sub

答案:k<=2^i ; loop

程序功能:计算s=2!+4!+6!+8!。程序中有错误。改正错误,使它能输出正确的结果。 41066)

Private Sub Command1_Click()

Dim k As Integer, i As Integer

Dim s As Long, t As Long

s = 0 : i = 1

Do While i <= 4

t = 1

k = 1

While k <= 2^i

t = t * k

k = k + 1

Wend

s = s + t

i = i + 1

wend

Print s

End Sub

答案:k<=2*i ; loop

程序功能:求200到400间,能被3整除但不能被7整除的数的个数。程序中有两行有错误。改正错误,使它能输出正确的结果。57)

Private Sub Command1_Click()

Dim count As Integer

Dim x As Integer

count = 0

x = 200

While x <= 400

If x Mod 3 = 0 or x Mod 7 <> 0 Then

count = count + 1

End If

x = x + 1

Loop

Print count

End Sub

答案: and ; wend

程序功能:求1到400间,同时能被3和7整除的数的个数。程序中有两行有错误。改正错误,使它能输出正确的结果。(19

Private Sub Form_Click()

Dim count As Integer

Dim x As Integer

For x = 1 To 400

if mod(x,3)=0 and mod(x,7)=0 then

count = count + 1

end if

Next count

Print count

End Sub

答案:x Mod 3 = 0 And x Mod 7= 0; x

程序功能:求能被3整除且至少有一位数字为5的三位数的个数。程序中有两行有错误。改正错误,使它能输出正确的结果。(85

Private Sub Command1_Click()

Dim count As Integer

Dim a As Integer, b As Integer, c As Integer

Dim x As Integer

x = 100

do While x <= 999

If x Mod 3 = 0 Then

a = Int(x / 100)

b = Int((x - a * 100) / 10)

c = x - a * 100 - b * 10

If a = 5 and b = 5 and c = 5 Then

count = count + 1

End If

End If

x = x + 1

wend

Print count

End Sub

答案:a = 5 or b = 5 or c = 5 ; loop

程序功能:求三位偶数中,个位数字与十位数字之和除以10所得的余数是百位数字的数的个数。程序中有两行有错误。改正错误,使它能输出正确的结果。(45

Private Sub Command1_Click()

Dim count As Integer

Dim a As Integer, b As Integer, c As Integer

Dim x As Integer

count = 0

x = 100

While x <= 999

a = Int(x /

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值