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
x
from the user. - Input Number of Terms: Read the number of terms
n
to be added in the series. - Initialize Variables:
- Set
term
to 1. - Set
sum
to 0.
- Set
- Calculate Series:
- Loop from
i = 1
ton
:- Add
term
tosum
. - Update
term
asterm * x / i
.
- Add
- Loop from
- Display Result:
- Print the result of
e^x
up ton
terms.
- 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