Q. Write a program to find the sum of the following series:

(a) x – x2 /2! + x3/3! …….. – x6/6!

(b) x + x2/2 ……… + xn/n (input x and n both)


You can understand by Watching video :-



Answer :-

(a).

x = int(input("Enter a term = "))
fact = 1
sum = 0
for i in range(1,7):
    fact = fact * i
    if i % 2 == 0 :
        sum = sum - (x**i)/fact
    else :
        sum = sum + (x**i)/fact
print("Sum of series = ",sum)

(b).

x = int(input("Enter x = "))
n = int(input("Enter n = "))
sum = 0
for i in range(1,n+1):
    sum = sum + x**i/i
print("Sum of series = ",sum)

Output :-

(a).

Enter x = 5
Sum of series =  -8.368055555555557

>>> 

Enter x = 4
Sum of series =  -1.155555555555556

>>> 

(b).

Enter x = 5
Enter n = 5
Sum of series =  840.4166666666666

>>> 

Enter x = 40
Enter n = 6
Sum of series =  703808840.0

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post