include cmath include stdio int main double sum double double term dou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cmath>
#include <stdio.h>
int main()
{
double sum=0;
double x;
double term=1;
double e=0.00001;
int n=1;
double prev_sum;
printf("Input X: ");
scanf("%lf",&x);
do{
term*=(x-1)/x;
prev_sum=sum;
sum+=term/n;
n++;
}while(prev_sum == 0 || (1-sum/prev_sum)>e || (1-sum/prev_sum)< -e);
printf("sum=%lf",sum);
system("PAUSE");
return 0;
}