[资料]vb编程题库0
VB编程题库0
1输入圆的半径,计算圆的面积,并输出。 Private Sub Command1_Click() Dim r!, s!
r = InputBox("请输入半径", "输入框") s =
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
编写程序,建立一个 6×6的整型二维数组(数据由程序调用Rnd函
数产生[0,15 )的随机整数数),输出数组中的最大元素。
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=,编写程序, 计算并输出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 =
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)
如果是求大写字母就把97改为65
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
用VB编写程序,判断100到200之间的素数,并求和
Private Sub Comman
[资料]vb编程题库0 来自淘豆网www.taodocs.com转载请标明出处.