Está en la página 1de 1

Private Function Factorial(ByVal n As Integer) As Integer Dim fact As Integer = 1 If n > 0 Then For i As Integer = 1 To n fact *= i Next ElseIf

n < 0 Then Throw New Exception("Value must not be negative") End If Return fact End Function Private Function CalculatePb(ByVal A As Double, ByVal N As Integer) As Double Pb As Double numerator As Double = A ^ N / Factorial(N) denominator As Double = 0.0 x As Integer = 0 To N Step 1 denominator += A ^ x / Factorial(x) Next x If denominator > 0 Then Pb = numerator / denominator End If Return Pb End Function To use it, you just call the Function and pass in values for A & N VB Code: Dim Pb As Double = CalculatePb(3, 6) 'Show the result with 4 decimal places MsgBox(Pb.ToString("F4")) Dim Dim Dim For

También podría gustarte