<!-- hamlet
<!-- copytar
examples/                                                                                           0040755 0001107 0000172 00000000000 05661730345 0014263 5                                                                                                    ustar 00zachary                         cs-teach                        377777770000021                                                                                                                                                                        examples/kelvin.c                                                                                   0100644 0001107 0000172 00000000636 05660762453 0015725 0                                                                                                    ustar 00zachary                         cs-teach                        377777770000021                                                                                                                                                                        #include <stdio.h>

/* This program repeatedly prompts the user for a positive temperature
   in degrees Kelvin and then prints it out.  It illustrates the use of
   a while loop. */

void main () {

  float temp;

  temp = -1.0;
  while (temp <= 0) {
    printf("Please enter a (positive) temperature in degrees Kelvin: ");
    scanf("%f", &temp);
  }

  printf("The temperature you entered was: %g\n", temp);

}
                                                                                                  examples/bisection.c                                                                                0100644 0001107 0000172 00000001002 05660777132 0016400 0                                                                                                    ustar 00zachary                         cs-teach                        377777770000021                                                                                                                                                                        #include <stdio.h>
#include <math.h>

/* Computes an approximate root {\tt x} of the function {\tt f} using the
   bisection method.  We assume that f(neg) is negative and that f(pos) is
   positive.  Guarantees that a true root will be somewhere in the interval
   [x-.5e-5 ... x+.5e-5]. */

float bisection (float neg, float pos) {

  float ave;

  while (abs(pos-neg) > 1e-5) {
    ave = (pos + neg) / 2;
    if (f(ave) < 0) {
      neg = ave;
    }
    else {
      pos = ave;
    }    
  }

  return(ave);

}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              examples/summation.c                                                                                0100644 0001107 0000172 00000000700 05661727632 0016442 0                                                                                                    ustar 00zachary                         cs-teach                        377777770000021                                                                                                                                                                        #include <stdio.h>

/* This program prompts the user for a value for "n" and then does
   the summation

    n
   -----
   \        1
    \      ___
    /      
   /____    2i

   i = 1

*/

void main () {

  float sum;
  int i;
  int n;

  printf("Enter a positive integer to limit the summation: ");
  scanf("%d", &n);

  sum = 0.0;
  i = 1;

  while (i <= n) {
    sum = sum + 1/(2.0*i);
    i = i + 1;
  }

  printf("The sum is %f\n", sum);

}
   }
    else {
      pos = ave;
    }    
  }

  return(ave);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                