please check my homework



This is a homework assignment for extra credit. The statistical material has not been covered in class. Is my bidist() function correct? It seems to work with the examples I have tried, but I would appreciate your comments and suggestions. PLEASE don't write any code. Error checking deliberately omitted for now and I am aware of the potential for factorials to exceed LDBL_MAX.

David
---------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long double bidist(long double p, long double n, long double x);
long double factorial(long double n);

int main(int argc, char *argv[])
{
    long double pp, nn, xx, result;

    if(argc != 4) exit(EXIT_FAILURE);

    pp = strtold(argv[1], NULL);
    nn = strtold(argv[2], NULL);
    xx = strtold(argv[3], NULL);

    result = bidist(pp, nn, xx);
    printf("%Lf\n", result);

    return 0;
}

/* return the probability of x successes in n events,
   given the probability p for success in a single event,
   using the formula for the binomial distribution:
              n!
   f(x) = --------- ( p^x )( (1-p)^(n-x) )
          x! (n-x)!
*/
long double bidist(long double p, long double n, long double x)
{
    long double fn, fx, fnx, t1, t2, t3;

    fn = factorial(n);
    fx = factorial(x);
    fnx = factorial(n-x);
    t1 = fn / (fx * fnx);
    t2 = (long double)pow(p, x);
    t3 = (long double)pow(1.0-p, n-x);

    return t1 * t2 * t3;
}

/* return n! */
long double factorial(long double n)
{
  long double f;

  f = 1.0;
  while(n > 1.0)
    f *= n--;

  return f;
}
.