(Python)Find sum of factorial series: x-x^2/2!+X^4/4!-x^6/6!.......n
Answers
Answered by
4
Question :-
- WAP in python to find the sum of the series
x - x^2/2! + x^4/4! - x^6/6!....nth term
Code Logic :-
- Even terms are negative and odd terms are positive
- numerator = x raised to power i
- denominator= factorial of i
Variable Description :-
- f:- to calculate factorial of i
- j:- loop variable
- i:- loop variable
- n:- to Accept no. of terms from the user
- x:- to accept value of 'x' from the user
- s:- to calculate sum
Code Explanation :-
- the program accepts the no. of terms and the value of x from the user
- f and s are initialized to 1 and 0 respectively
- Then the program runs i Loop from 1 to n
- Then it run j loop from 1 to i to calculate factorial of I
- if I loop Value is even then it substract the terms from its previous value
- else if I loop value is odd then it adds the terms
- when I loop value becomes greater than n then loop terminates
- sum gets printed
Attachments:
Similar questions