1 / 11

# VB程序设计编程考试题及答案.pdf

private Sub Command1_Click()
n1 = InputBox("输入 n")
m1 = InputBox("输入 m")
If m1 > n1 Then
m = m1: n = n1
Else
m = n1: n = m1End If
r = m Mod n
Do While r <> 0
m = n
n = r
r = m Mod n
Loop
Print "m n 的最大公约数是："; n
End Sub
8. 编程求 200--400 范围内 5 的倍数或 7 的倍数之和。(一个数如果同时是 7 和 5 的倍数，则

Private Sub Command1_Click()
For i = 200 To 400
If i Mod 5 = 0 Or i Mod 7 = 0 Then
Sum = Sum + i
End If
Next i

For i = 200 To 400
If i Mod 5 = 0 And i Mod 7 = 0 Then
Sum = Sum - i
End If
Next i

Print “倍数之和=”; Sum
End Sub
9. 计算 100~300 之间所有能被 3 和 7 整除的数之和
Private Sub Command1_Click()
Dim i
Sum = 0
For i = 100 To 300
If i Mod 3 = 0 And i Mod 7 = 0 Then
Sum = Sum + i
End If
Next i
Print Sum
End Sub
10. 分别统计 1-100 中，满足 3 的倍数、7 的倍数的数各有多少。
Private Sub Command1_Click()
Dim i, s3, s7
s3 = 0
s7 = 0
For i = 1 To 100If i Mod 3 = 0 Then
s3 = s3 + 1
End If
Next i
For i = 1 To 100
If i Mod 7 = 0 Then
s7 = s7 + 1
End If
Next i
Print "3 的倍数"; s3
Print "7 的倍数"; s7
End Sub
11. 某次歌曲大奖赛，有 7 个评委。如果分别输入 7 个评委对某个参赛者的打分数，按照去

Private Sub Command1_Click()
Dim max, a(1 To 7), min, s
For i = 1 To 7
a(i) = Val(InputBox("输入第" & i & "个数"))
Next i
max = a(1)
min = a(1)
s = a(1)
For i = 2 To 7
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
s = s + a(i)
Next i
s = s - min - max
s = s / 5
Print "平均分"; s
End Sub
12. 输入一串字符，统计其中字母 A(不区分大小写)出现的次数

# VB程序设计编程考试题及答案.pdf

VB程序设计编程考试题及答案.pdf