递归算法实例:阶乘(vb.net代码)
生活随笔
收集整理的這篇文章主要介紹了
递归算法实例:阶乘(vb.net代码)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Public Class frmMainPrivate Sub 更新下載ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 更新下載ToolStripMenuItem.ClickProcess.Start("https://pan.baidu.com/s/1uHZturISzQifxeHL-FX-eQ")My.Computer.Clipboard.Clear()My.Computer.Clipboard.SetText("e832")MsgBox("提取碼e832已復制,直接到網(wǎng)頁粘貼即可")End SubPrivate Sub 作品集ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 作品集ToolStripMenuItem.ClickProcess.Start("https://pan.baidu.com/s/1jr_3Yt5l1i6jNNbMy4R61A")My.Computer.Clipboard.Clear()My.Computer.Clipboard.SetText("5ycz")MsgBox("提取碼5ycz已復制,直接到網(wǎng)頁粘貼即可")End SubPrivate Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.LoadlblTell.Text = "階乘示例6!=6*5*4*3*2*1"txtNum.Text = "6"End SubPrivate Sub btnResult_Click(sender As Object, e As EventArgs) Handles btnResult.ClickIf IsNumeric(txtNum.Text) ThenTryDim intNum As Integer = CInt(txtNum.Text)If intNum > 0 Then'計算階乘結(jié)果Dim lngResult As Long = fact(intNum)'比較輸入結(jié)果與計算結(jié)果是否一致'錯誤或未輸入結(jié)果時,輸出正確結(jié)果If IsNumeric(txtResult.Text) ThenIf lngResult = CLng(txtResult.Text) ThenMsgBox("你好厲害,能口算階乘結(jié)果!")ElseMsgBox("結(jié)果錯誤")txtResult.Text = lngResultEnd IfElsetxtResult.Text = lngResultEnd IfElseMsgBox("錯誤,數(shù)字不能小于1")End IfCatch ex As ExceptionMsgBox("錯誤,數(shù)字超出正常范圍")End TryElseMsgBox("錯誤,不是數(shù)字")End IfEnd SubPrivate Function fact(ByVal intN As Integer) As Long'階乘計算,遞歸函數(shù)If intN > 1 ThenReturn intN * fact(intN - 1)ElseReturn 1End IfEnd FunctionPrivate Sub 代碼瀏覽ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 代碼瀏覽ToolStripMenuItem.ClickProcess.Start("https://blog.csdn.net/kguncn/article/details/109010514")End Sub
End Class
總結(jié)
以上是生活随笔為你收集整理的递归算法实例:阶乘(vb.net代码)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jupyter notebook代码导出
- 下一篇: 怎么看电脑电源多少w_UPS不间断电源设