/* Title: Test function sf(x) This will test the function 'sf' given in Section 3 of Chapter 1. When the program is running, let the input variable x equal 0 to stop. */ #include float sf(float x); main() { float x; while (1) { printf("\n\tWhat is x? Give 0 to stop : "); scanf("%f", &x); if (x == 0.0) return(0); printf("\n\t x = %f \t sf(x) = %f\n", x, sf(x)); } } float sf(float x) { /* This evaluates an approximation to 1 x 1 sf(x) = - integral - sin(t)*dt x 0 t For -1 <= x <= 1, the approximation is the degree 8 Taylor polynomial for sf(x). Its maximum error is 5.0e-9, provided the computer arithmetic allows a relative error of that size. */ float u, value, a[5] = { 1.0, -1.0/18.0, 1.0/600.0, -1.0/35280.0, 1.0/3265920.0 }; int ndeg = 4, i; /* Initialize */ u = x*x; value = a[ndeg]; /* Do nested multiplication */ for (i = ndeg; i >= 0; i--) value = a[i] + u*value; return(value); }