The C program in Fig. 12.4.1 computes sin(x) by using a power series. The interior of the loop is executed many times, while the code before and after the loop is executed only once. The interior of the main for loop is called a hot spot. #include <stdio.h> #include <stdlib.h> #define NUMTERMS 1 main() { double sum, x, xpower, fact; int i, sign, k; printf ("Enter angle in radians: "); scanf ("%lf", &x); sum = x; sign = -1; k = 3; fact = 1; xpower = x; for (i=1; i<NUMTERMS; i++) { +--------------------------------+ | xpower *= x * x; | | fact *= (k-1) * k; | | sum += sign * xpower / fact; | | k += 2; | | sign = -sign; | +--------------------------------+ } printf ("sin(%15.8f radians) = %15.8f\n", x, sum); } Fig. 12.4.1: C program to compute sin(x); Hot spot is indicated by the outline |