Private Function a%(b)
創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)蒼梧,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
s = 1
For i = 1 To b
s = s * i
Next i
a = s
End Function
Private Sub Form_activate()
For i = 1 To 10
n = n + a(i)
Next i
Print n
End Sub
首先在窗體上畫兩個控件:TextBox1和Button1
TextBox1用來輸入需要計算那個數(shù)的階乘
雙擊Button1進(jìn)入輸入代碼,代碼如下
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim Factorial As Integer = 1 '定義一個變量用來記錄階乘的結(jié)果
Dim count As Integer '定義一個變量用來記錄需要計算那個數(shù)的階乘
Dim i As Integer = 1 '定義一個數(shù)用來循環(huán)
count = Int(Val(Me.TextBox1.Text)) '把TextBox1的值賦值給count
Do While i = count '下面開始計算階乘
Factorial = Factorial * i '計算階乘
i += 1 '自增1
Loop
MessageBox.Show(Int(Val(Me.TextBox1.Text)) "的階乘是:" Factorial, "完成", MessageBoxButtons.OK) '彈出計算結(jié)果
Catch ex As Exception '出錯提示
MessageBox.Show(Err.Description, "出錯了", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Command1_Click()
Dim A, B, C
A = 10
B = 3
C = f(A) / (f(B) * f(A - B))
Print C
End Sub
Private Function f(n)
Dim I As Integer
f = 1
For I = 1 To n
f = f * I
Next I
End Function