Example description
/* nag_deviates_chi_sq (g01fcc) Example Program.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.2, 2017.
 */

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

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

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_deviates_chi_sq (g01fcc) Example Program Results\n");
  printf("     p       df      x\n\n");
  while (scanf("%lf %lf", &p, &df) != EOF)
  {
    /* nag_deviates_chi_sq (g01fcc).
     * Deviates for the chi^2 distribution
     */
    x = nag_deviates_chi_sq(p, df, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_deviates_chi_sq (g01fcc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%8.3f%8.3f%8.3f\n", p, df, x);
  }

END:
  return exit_status;
}