/* --------------------------------------------------------------------- // Figure 4.14: Using increment in a loop. // --------------------------------------------------------------------- */ #include void main( void ) { int N; int x = 0; /* Loop counter. */ double sum = 0.0; /* Sum of terms 1/x. */ puts( "\n Summing 1.0/x for x between 1 and N.\n" ); printf( " Please enter an integer N greater than 1: " ); scanf( "%i", &N ); if (N <= 1) { /* Screen out faulty inputs. */ printf( "\n Input value %i is too small.\n\n", N ); } else { while (x < N) { ++x; sum += 1.0 / x; } printf( " The sum is %g \n\n", sum ); } }