There so many mathematical series. One of the series is given below. And we use different programming language to print the sum or the series in faster. Because calculating the sum is bit tougher. So we think better to use computer languages. And here is the optimize program to print the series and sum.
2 - 5 + 8 - ........................................
9 13 17
# Program to print the series and sum too.
# Here enter the number of elements.
n = int(input("Enter number :"))
sum = 0.0
i = 1
a = 2
b = 9
while i <= n :
if i%2 == 0 :
sum = sum+(a/b)*(-1)
print((-1)*a,"/",b, end=',')
else :
sum = sum+(a/b)
print(a,"/",b, end=',')
a += 3
b += 4
i += 1
print()
print(sum)
Comments