wap to x+x^2/2+x^3/3+...........x^n/n
#include <iostream>
#include <cmath>
using namespace std;
double calculateS(double x, int n) {
double Sum = 0.0;
for (int i = 1; i <= n; i++) {
Sum += pow(x, i) / i;
}
return Sum;
}
int main() {
double x;
int n;
cout << "Enter the value of x: ";
cin >> x;
cout << "Enter the pow value: ";
cin >> n;
double Sum = calculateS(x, n);
cout << "The sum of the series is: " << Sum << endl;
return 0;
}
Output 1:-
Enter the value of x:1
Enter the pow value :5
the sum of the series is :2.2833
Output 2:-
Enter the value of x:2
Enter the pow value :6
the sum of the series is :27.7333