1 / 17

# [资料]vb编程题库0.doc

VB编程题库0
1输入圆的半径，计算圆的面积，并输出。 Private Sub Command1_Click() Dim r!, s!
r = InputBox("请输入半径", "输入框") s = 3.1的和
Option Base 1
Private Sub Form_Click() Randomize
Dim a(1 To 5, 1 To 5) For i = 1 To 3
For j = 1 To 3
a(i, j) = Int(Rnd * 21)
Print a(i, j); " ";
Next j
Print
Next i
c = "每列相加的值是:" & vbCrLf For i = 1 To 3
For j = 1 To 3
t = t + a(j, i)
Next j
c = c & t & " "
t = 0
Next i
Print c
End Sub

Option Base 1
Private Sub Command1_Click() Dim a(6, 6) As Integer
Randomize
Max = a(1, 1)
For i = 1 To 6
For j = 1 To 6
a(i, j) = Int(Rnd * 16 + 0)
If a(i, j) > Max Then
Max = a(i, j)
End If
Print a(i, j);
n = n + 1
If n Mod 6 = 0 Then
Print
End If
Next j
Next i
Print "最大元素为:"; Max End Sub

Option Base 1
Private Sub Command1_Click() Dim a()
a() = Array(1, 2, 3, 4, 5, 6, 7, 8, 9) Print "数组中所有元素的平均值为:" & ave(a())
End Sub
Private Function ave(a())
For i = 1 To UBound(a)
Sum = Sum + a(i)
Next i
ave = Sum / UBound(a)
End Function
5编写程序，计算并输出下面级数前n项(n=50)中偶数项的和。
s = 1*2+2*3+3*4+4*5+„„+n*(n+1)+„ 22750
Private Sub Form_Activate() s = 0
For I = 2 To 50 Step 2 s = s + I * (I + 1)
Next I
Print s
End Sub
6编写程序， 设n=20，x=3.4，编写程序， 计算并输出S(n)的值，要求结果保留5位小数。S(n)=lnx/x+ln2x/x^2+ln3x/x^3+„+ln(n*x)/x^n+„(其中，ln为

Private Sub Command1_Click() Const x = 3.4
For n = 1 To 20
s = s + Log(n * x) / x ^ n Next n
Print Format(s, "0.#####") End Sub
7随机输出一个小写字母
Dim letterasscii, i%, letter\$ letterascii = Int(Rnd * 26) + 97 letter = Chr(letterascii) Print letter
MsgBox (letter)

8编写一个函数，其功能为判断某个整数是不是素数并判断100001

Private Sub Form_Click() Dim n, i#
n = InputBox("n=")
i = 2
While n Mod i <> 0
i = i + 1
Wend
If i = n Then
Print n & "是素数"
Else
Print n & "不是素数"
End If
End Sub

Private Sub Comman

[资料]vb编程题库0.doc