Evaluate the Series e2
This program calculates the value of the series ex using the formula: ex = 1 + x/1! + x2/2! + x3/3! + .... + xn/n! It prompts the user to enter the value for x and the number of terms n to include in the series. The program then computes the sum of the series up to n terms and displays the result.
Code Breakdown
Algorithm
- Start
- Input Value for x: Read the value of
xfrom the user. - Input Number of Terms: Read the number of terms
nto be added in the series. - Initialize Variables:
- Set
termto 1. - Set
sumto 0.
- Set
- Calculate Series:
- Loop from
i = 1ton:- Add
termtosum. - Update
termasterm * x / i.
- Add
- Loop from
- Display Result:
- Print the result of
e^xup tonterms.
- Print the result of
- End
Code Explanation
Example Flowchart
Start
|
V
Input value for x
|
V
Input number of terms n
|
V
Initialize term = 1, sum = 0
|
V
For i = 1 to n
|
V
Add term to sum
|
V
Update term as term * x / i
|
V
End of loop
|
V
Display result e^x = sum
|
V
End