/* nag_real_polygamma (s14aec) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * NAG C Library
 *
 * Mark 6, 2000.
 */

#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nags.h>

int main(void)
{
  Integer  exit_status = 0, k;
  NagError fail;
  double   x, y;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_real_polygamma (s14aec) Example Program Results\n\n");
  printf("   x      k    (d^k/dx^k)psi(x)\n");
  while (scanf("%lf %ld%*[^\n]", &x, &k) != EOF)
    {
      /* nag_real_polygamma (s14aec).
       * Derivative of the psi function psi(x)
       */
      y = nag_real_polygamma(x, k, &fail);
      if (fail.code == NE_NOERROR)
        printf("%5.1f %5ld     %13.4e\n", x, k, y);
      else
        {
          printf("Error from nag_real_polygamma (s14aec).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
    }
 END:
  return exit_status;
}