/* ACMPROB4.C Solution to the ACM East Central Region Programming Contest Problem #4 - Summation of a series */ #include main() { long k; /* dummy summation variable */ long n; /* number of terms to sum */ double kd; /* double version of k */ double x; /* the variable */ double sum; /* used for computation summations */ double px, p1; /* psi(x) and psi(1) */ double dpx; /* value of the first accelerated series at x */ double dp2; /* value of the first accelerated series at 2 */ double ddpx; /* value of the second accelerates series at x */ long i; /* counter for elements of table */ p1 = 1.0; dp2 = 0.25; n = 2000; /* evaluation of the error term for the summation e = 1.0 / ( ( r+1.0)*pow((double)n+1.0,(couble)r-1.0));, shows that n=120000 is large enough. If the first improved sequence is used. With approximately 16 digits of precision in a double precision variable, adding this many positive decreasing terms will not effect the desired final precision, but it is close. For even more speed and more precision without roundoff, a second application of the acceleration method produces a similar series which requires only 2000 term. */ /* loop for the 21 table entries */ for (i=0; i<21; i++ ) { x = i * 0.1; /* sum second accelerated series */ sum = 0.0; for( k=1; k