1、vb程式碼中,求一個數的階乘的函式程式碼如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End Function2、具體用法:首先開啟VB6.0,新建一個標準exe工程;3、在設計介面上新增一個Command控制元件,Command1的Caption屬性設定為"N的階乘"。4、雙擊Command1控制元件進入程式碼編輯介面,編輯程式碼如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End FunctionPrivate Sub Command1_Click()Dim sum As Double, n As Integern = InputBox("計算的N的階乘,請輸入數字N")sum = jiecheng(n)MsgBox (sum)End Sub5、執行新建的工程,單擊按鈕,輸入要計算的N的階乘的數字N,得出階乘結果。
1、vb程式碼中,求一個數的階乘的函式程式碼如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End Function2、具體用法:首先開啟VB6.0,新建一個標準exe工程;3、在設計介面上新增一個Command控制元件,Command1的Caption屬性設定為"N的階乘"。4、雙擊Command1控制元件進入程式碼編輯介面,編輯程式碼如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End FunctionPrivate Sub Command1_Click()Dim sum As Double, n As Integern = InputBox("計算的N的階乘,請輸入數字N")sum = jiecheng(n)MsgBox (sum)End Sub5、執行新建的工程,單擊按鈕,輸入要計算的N的階乘的數字N,得出階乘結果。