Sum of the series
Write a program to find the sum
S of the series where S = x - x^3 + x^5 + ....... upto N terms.
Sample Input 1
2
5
Sample Output 1
410
to solve this approch
if i value is even:
result = summation of the term value and then added to the result
else :
result = Subtraction of the term value and then added to the result
x = int(input())
n = int(input())
sign = 1
buff = 0
pow = 1
for i in range(n):
buff += sign*x**pow
sign *= -1
pow += 2
print(buff)
Comments
Leave a comment