NAG Library Manual, Mark 30.3
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_univar_ci_binomial (g07aac) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.3, 2024.
 */

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

int main(void) {

  /* Scalars */
  double clevel, phat, pl, pu;
  Integer exit_status = 0, k, n;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_univar_ci_binomial (g07aac) Example Program Results\n");

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

  printf("\n");
  printf(" Probability    Confidence Interval\n");
  printf("\n");
  while (scanf("%" NAG_IFMT "%" NAG_IFMT "%lf%*[^\n] ", &n, &k, &clevel) != EOF)
  {
    phat = (double)k / (double)n;
    /* nag_univar_ci_binomial (g07aac).
     * Computes confidence interval for the parameter of a
     * binomial distribution
     */
    nag_univar_ci_binomial(n, k, clevel, &pl, &pu, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_univar_ci_binomial (g07aac).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }

    printf("%10.4f      ( %6.4f , %6.4f )\n", phat, pl, pu);
  }

END:
  return exit_status;
}