Anda di halaman 1dari 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 Dim Pb As Double Dim numerator As Double = A ^ N / Factorial(N) Dim denominator As Double = 0.0 For 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

Anda mungkin juga menyukai