Example description
/* nag_quad_dim1_gauss_wres (d01tbc) Example Program.
 *
 * Copyright 2020 Numerical Algorithms Group.
 *
 * Mark 27.1, 2020.
 */

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

int main(void) {
  Integer exit_status = 0;
  Integer n;
  double a, b;
  Integer i;
  Nag_QuadType quadtype;
  NagError fail;
  double *abscis = 0, *weight = 0;

  INIT_FAIL(fail);

  printf("nag_quad_dim1_gauss_wres (d01tbc) Example Program Results\n");
  /* Skip heading in data file */
  scanf("%*[^\n] ");
  /* Input a, b and n */
  scanf("%lf %lf", &a, &b);
  scanf("%" NAG_IFMT "%*[^\n] ", &n);
  quadtype = Nag_Quad_Gauss_Laguerre_Adjusted;

  if (!(abscis = NAG_ALLOC(n, double)) || !(weight = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* nag_quad_dim1_gauss_wres (d01tbc).
   * Pre-computed weights and abscissae for
   * Gaussian quadrature rules, restricted choice of rule.
   */
  nag_quad_dim1_gauss_wres(quadtype, a, b, n, weight, abscis, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_quad_dim1_gauss_wres (d01tbc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\nLaguerre formula, %3" NAG_IFMT " points\n\n"
         "    Abscissae        Weights\n\n",
         n);
  for (i = 0; i < n; i++) {
    printf("%15.6e", abscis[i]);
    printf("%15.6e\n", weight[i]);
  }
  printf("\n");

END:
  NAG_FREE(abscis);
  NAG_FREE(weight);

  return exit_status;
}