45 - Write a program in Python to input the value of x and n and print the sum of the following series:
x + x2/2 + x3/3 + x4/4 + -------- xn /n
x=int(input("Enter the value of x: "))
n=int(input("Enter the value of n: "))
sum=0
for i in range(1,n+1):
sum=sum+pow(x,i)/i
print("Sum of the series=",sum)
Output:
Enter the value of x: 2
Enter the value of n: 3
Sum of the series= 6.666666666666666
Enter the value of x: 2
Enter the value of n: 4
Sum of the series= 10.666666666666666
No comments:
Post a Comment