9、Visual Basic程序改错
1.程序功能:求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
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
3.程序功能:计算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二级VB
Print s
End Sub
答案:k<=2*i ; loop
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
5.程序功能:求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
6.程序功能:求能被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
7.程序功能:求三位偶数中,个位数字与十位数字之和除以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 / 100)
b = Int(x / 10) - a * 10
c = x - a * 100 - b * 10
If Mod(x,2) = 0 or mod(b + c,10) = a Then count = count + 1
End If
x = x + 1
loop
Print count
End Sub
答案:x Mod 2 = 0 And (b + c) Mod 10 = a; wend
8.程序功能:求平方和小于2000的最大自然数。程序中有两行有错误。改正错误,使它能输出正确的结果。
(18)
Private Sub Form_Click()
Dim x As Integer
Dim s As Integer
s = 0
x = 0
Do While s >= 2000
x = x + 2
s = s + x * x
loop
Print x
End Sub
答案:s<=2000 ; x = x + 1
9.程序功能:解百马百瓦古题。大、小马和马驹共100匹,共驮100片瓦。大马一驮三,小马一驮二,马驹二驮一,一次驮完,三种马都驮,共有多少种组合? 程序中有三行有错误。改正错误,使它能输出正确的结果。( 6 )
新垣 senaPrivate Sub Form_Click()
发布评论