/* nag_hypergeom_dist (g01blc) Example Program.
 *
 * NAGPRODCODE Version.
 *
 * Copyright 2016 Numerical Algorithms Group.
 *
 * Mark 26, 2016.
 *
 */

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

int main(void)
{
  Integer exit_status = 0;
  double plek, peqk, pgtk;
  Integer k, l, m, n;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_hypergeom_dist (g01blc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");

  printf("\n    n   l   m   k     plek      pgtk      peqk\n\n");
  while ((scanf
          ("%" NAG_IFMT " %" NAG_IFMT " %" NAG_IFMT " %" NAG_IFMT "%*[^\n]",
           &n, &l, &m, &k)) != EOF) {
    /* nag_hypergeom_dist (g01blc).
     * Hypergeometric distribution function
     */
    nag_hypergeom_dist(n, l, m, k, &plek, &pgtk, &peqk, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_hypergeom_dist (g01blc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf(" %4" NAG_IFMT "%4" NAG_IFMT "%4" NAG_IFMT "%4" NAG_IFMT
           "%10.5f%10.5f" "%10.5f\n", n, l, m, k, plek, pgtk, peqk);
  }

END:
  return exit_status;
}