/* nag_incomplete_beta (s14ccc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 */

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

int main(void)
{
  Integer  exit_status = 0;
  double   a, b, x, w, w1;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_incomplete_beta (s14ccc) Example Program Results\n");

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

  printf("%4s%7s%7s%13s%13s\n","a","b","x","Ix(a,b)","1-Ix(a,b)");
  while (scanf("%lf %lf %lf", &a, &b, &x) != EOF)
    {
      /* nag_incomplete_beta (s14ccc).
       * Incomplete beta function Ix(a,b) and its complement 1-Ix(a,b)
       */
      nag_incomplete_beta(a, b, x, &w, &w1, &fail);
      if (fail.code != NE_NOERROR)
        {
          printf("Error from nag_incomplete_beta (s14ccc).\n%s\n",
                 fail.message);
          exit_status = 1;
          goto END;
        }
      printf("%6.2f%7.2f%7.2f%12.4e%12.4e\n", a, b, x, w, w1);
    }

 END:
  return exit_status;
}