/* nag_binomial_dist (g01bjc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0; Integer k, n; double plek, peqk, pgtk; double p; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_binomial_dist (g01bjc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fprintf(fpout, "\n"); fprintf(fpout, " n p k plek pgtk peqk\n\n"); while ((fscanf(fpin, "%ld %lf %ld%*[^\n]", &n, &p, &k)) != EOF) { /* nag_binomial_dist (g01bjc). * Binomial distribution function */ nag_binomial_dist(n, p, k, &plek, &pgtk, &peqk, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_binomial_dist (g01bjc)\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%5ld%8.3f%5ld%10.5f%10.5f%10.5f\n", n, p, k, plek, pgtk, peqk); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }