/* program to compute a circle's circumference and area example using an array
   of functions as a parameter
 */

#include <stdio.h>
#include <math.h>

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


/* calculate the circumference of a circle given its radius */
double
circum (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 each function in an array applied to the given radius */
void
printArr(double radius, double (*funcarr[])(double) )
{
  for (int f = 0; f < 3; f++)
    printf ("%12.4lf", funcarr[f](radius));
  printf ("\n");
} // printArr


/* print the values of a set of functions for 10 radii */
int
main (void)
{
  double (*funcArr[3]) (double) = {identity, circum, area};
  printf ("      radius   circumference   area\n");
  
  for (double radius = 0; radius < 10; radius++)
    printArr (radius,funcArr);

  return 0;
} // main
