# WAP in C++ & Python to find the sum of the series x+ x2/2 +x3/3 + ……. +xn/n

By | September 7, 2019

Here in this program, we will code to calculate the sum of a special series x + x2/2 +x3/3 + ……. +xn/n, where x and n are two variables which value the user will enter.

### C++ Program to find the sum of the series x+x^2/2+x^3/3+…..+x^n/n

```#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
long float sum=0,x,n,i;
cout<<"Here we will calculate the sum of series x + (x^2)/2+ ...+ (x^n)/n \n";
cout<<"Enter the value of x :";
cin>>x;
cout<<"Enter the value of n: ";
cin>>n;

for(i=1;i<=n;i++)
{
sum += pow(x,i)/i;
}
cout<<"The sum of the series is: "<<sum;
getch();
}```

Output:

```Here we will calculate the sum of series x+x^2/2+…..+x^n/n

Enter the value of x: 4
Enter the value of n: 5
The sum of the series is: 302.1333```

### Python Program to find the sum of the series x+x^2/2+x^3/3+…..+x^n/n

```import math
sum=0
print("Here we will calculate the sum of series x+x^2/2+…..+x^n/n")
x=int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
for i in range(1,n+1):
sum+=math.pow(x,i)/i
print("The sum of the series is:", sum)```

Output:

```Here we will calculate the sum of series x+x^2/2+…..+x^n/n

Enter the value of x: 4
Enter the value of n: 3
The sum of the series is: 33.333```