Faster, Higher, Stronger
更快,更高,更强

[转] VB想考满分吗。。。

一。随机数出一个小写字母

Private Sub Command1_Click()
Dim a As String
Randomize
a = Chr(Int(97 + 26 * 26))
MsgBox (a)
End Sub

二。计算1/1!+1/2!+。。。。+1|10!

Private Sub Command1_Click()
Dim m As Integer, n As Long, s As Double
n = 1
s = 0
For m = 1 To 10
n = n * m
s = s + 1 / n
Next
Print s
End Sub

三。编写一个函数,求两个数的最小数

Private Sub Form_Load()
Dim a%, b%
a = Val(InputBox(“a=”))
b = Val(InputBox(“b=”))
If a > b Then
Print “a>b”
Else
Print “a<b”
End If
End Sub

四。输入正方形的边长,并计算对角线长

Private Sub Form_Load()
Dim a%, b%
a = InputBox(“请输入a的值”)
b = Sqr(2) * a
Print “正方形的对角线长:”; b
End Sub
五。计算并输出下面级数前n项和中偶数项和s=1*2+2*3+3*4+4*5+。。。。+n*(n+1)

Private Sub Command1_Click()
Dim i%, sum%
For i = 1 To 50 Step 2
sum = sum + i * (i + 1)
Next i
Print sum
End Sub

六。编写一个函数,其功能是判断某个整数是不是素数,调用该函数,判断100001是否是素数

Private Sub Command1_Click()
Dim a%, i%
a = InputBox(“请输入a的值”)
For i = 1 To a
If a Mod i = 0 Then
m = m + 1
End If
Next i
If m = 2 Then
MsgBox (“a是素数”)
Else
MsgBox (“a不是素数”)
End If
End Sub
七。计算sum=1+3+5+…+99

Private Sub Command1_Click()
Dim i As Integer, sum As Integer
sum = 0
For i = 1 To 100 Step 2
sum = sum + i
Next
text1.Text = sum
End Sub

八。输入一个两位数,分别输入它的个位数字和十位数字

Dim a%, b%, c%
a=val(inputbox “a=” )
b = a Mod 10
c = a \ 10
Print “各位数字为:”; b; “十位数字为:”
End Sub
九。计算1/1!+1/3!+1/5!+…..+1/99!

Private Sub Form_Load()
Dim i%, sum%, fact%
For i = 1 To 9
fact = fact * i
If i Mod 2 = 0 Then
sum = sum
sum = sum + 1 / fact
Next
Print sum
End Sub

十。编写程序,建立一个6*6的整型二维数组(数据由程序调用rnd函数产生{0,15}的随机),输出数组中所有元素和

Private Sub Form_Load()
Option Base 1
For i = 1 To 6
For j = 1 To 6
a(i, j) = Int(Rnd * 15)
Next j
Next i
Sum = 0
For i = 1 To 6
For j = 1 To 6
Sum = Sum + a(i, j)
Next j
Next i
Print Sum
End Sub

赞(0) 打赏(金额可任意指定)
未经允许不得转载:峰间的云 » [转] VB想考满分吗。。。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏