/* --------------------------------------------------------------------- // Figure 6.9: Summing a series. // Compute the sum of the first N terms of the series 1/n // --------------------------------------------------------------------- */ #include "tools.h" #define N 10 void main( void ) { int n; /* Loop counter */ double sum; /* Accumulator */ banner(); printf( "\n Summing the series 1/n where n goes from 1 to %i \n", N ); sum = 0.0; /* Start accumulator at zero. */ for (n = 1; n <= N; ++n) { /* Sum series from 1 to N. */ sum = sum + 1.0 / n; } printf( " The sum is %g. \n", sum ); bye(); }