The function e* can be expressed as an infinite power series as follows: 4 1!2!3
ID: 3734137 • Letter: T
Question
The function e* can be expressed as an infinite power series as follows: 4 1!2!3!4! Or as a general term: .r n! Program requirements: Use a main program and two user-defined Function subprograms. In the main program, prompt the user to enter a value, x, to use in calculating e*. In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value-1 x 10-7) In the main program, output the answer (the calculated e value) Use a user-defined Function to calculate the exponential (e) function. Use a user-define Function to calculate a Factorial, N!Explanation / Answer
Imports System
Imports System.Collections.Generic
Imports System.Collections
Namespace demo
Public Class DemoTranslation
Public Shared Sub main()
Dim n As Integer
Dim x As Single, sume As Single = 0F
Console.Write("enter x,n values")
x = STDIN_SCANNER.nextFloat()
n = STDIN_SCANNER.nextInt()
For i As Integer = 0 To n
sume = CSng((sume + Math.Pow(x, i) / CSng(fact(i))))
Next
Console.Write("eˆx series is %f" & vbLf, sume)
End Sub
Public Shared Function fact(ByVal n As Integer) As Long
Dim f As Long = 1
If n = 0 OrElse n = 1 Then
Return 1
Else
For i As Integer = 1 To n
f = f * i
Return f
Next
End If
End Function
Public ReadOnly Shared STDIN_SCANNER As Scanner = New Scanner(System.)
End Class
End Namespace
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.