/* nag_real_polygamma (s14aec) Example Program.
 *
 * NAGPRODCODE Version.
 *
 * Copyright 2016 Numerical Algorithms Group.
 *
 * NAG C Library
 *
 * Mark 26, 2016.
 */

#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 %" NAG_IFMT "%*[^\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 %5" NAG_IFMT "     %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;
}