/* program to compute a circle's circumference and area example using function
   with a function parameter */

#include <stdio.h>
#include <math.h> /* Might provide constant M_PI */

/* Handle the not-compiler-defined case */
#ifndef M_PI
#define M_PI (3.14159265358979323846264338327950288)
#endif


/* identity function (return the value given) */
double
identity (double radius)
{
  return radius;
} // identity


/* calculate the circumference of a circle given its radius */
double
circumference (double radius)
{
  return 2 * M_PI * radius;
} // circum


/* calculate the area of a circle given its radius */
double
area (double radius)
{
  return M_PI * radius * radius;
} // area


/* print the value of a given function at the given value */
void
myPrint (double x, double func (double))
{
  printf ("%12.4lf", func (x));
} // myPrint


/* main processing */
int
main (void)
{
  printf ("      radius   circumference   area\n");
  double radius;
  for (radius = 0; radius < 10; radius++)
  {
    myPrint (radius, identity); /* could also be printf ("%12.4lf", radius); */
    myPrint (radius, circumference);
    myPrint (radius, area);
    printf ("\n");
  }
  return 0;
} // main
