求高手解答vb.net问题

2024-12-03 22:17:45
推荐回答(2个)
回答1:

就是要求你写出阶乘的算法(其实算法给你了,只是要求写代码实现而已)

按谈旁照题目的要卖侍宏求,在窗体上画一个NumericUpDown和button,代中册码如下:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(factorial(NumericUpDown1.Value))
End Sub

Private Function factorial(ByVal n As Integer) As Long

If n = 1 Then Return 1
Return n * factorial(n - 1)

End Function
End Class

回答2:

一个裤衡散按钮(Button1) 两个文字拦肆框(TextBox1, TextBox2)

If TextBox1.Text <> "胡氏" Then
If TextBox1.Text = 1 Then
TextBox2.Text = 1
Else
Try
Dim N As Long, RES As Long
N = TextBox1.Text
RES = N
Do Until N <= 1
RES = RES * (N - 1)
N -= 1
Loop
TextBox2.Text = RES
Catch ex As Exception
Dim N As Long, RES As String
N = TextBox1.Text
RES = N
Do Until N <= 1
RES = RES & "*" & (N - 1)
N -= 1
Loop
TextBox2.Text = RES
End Try
End If
End If