/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:33:14 */ /*FOR_C Options SET: ftn=u io=c no=p op=aimnv pf=,p_sbinom s=dbov str=l x=f - prototypes */ #include #include "fcrt.h" #include #include #include "p_sbinom.h" /* program DRSBINOM *>> 1998-05-12 DRSBINOM Krogh Ensure Pascal print output. *>> 1995-12-15 DRDBINUM Krogh Initial Code. *--S replaces "?": DR?BINOM, ?BINOM * * Test SBINOM for computing binomial coefficients. * Checks a large value computed with factorials, one a little larger * that is computed using log gamma, and then finds first that differs * from that obtained using the Pascal triangle. * */ /* PARAMETER translations */ #define BC1 32198785340494567031466236484400.e0 #define BC2 9880808670399701168713050486000.e0 #define NMAX 120 /* end of PARAMETER translations */ int main( ) { long int k, n; float p[NMAX-(0)+1], tp; /* ( 150 ) ( 151 ) * BC1 = ( ) BC2 = ( ) * ( 30 ) ( 29 ) */ printf("\n N K SBINOM True Col. 2 - Col. 1\n"); tp = sbinom( 150, 30 ); printf("%4d%4d%26.17e%26.17e%16.7e\n", 150, 30, tp, BC1, BC1 - tp); tp = sbinom( 151, 29 ); printf("%4d%4d%26.17e%26.17e%16.7e\n", 151, 29, tp, BC2, BC2 - tp); printf("\n N K SBINOM Pascal Col. 2 - Col. 1\n"); p[0] = 1.e0; for (n = 0; n <= NMAX; n++) { for (k = 0; k <= n; k++) { tp = sbinom( n, k ); if (tp != p[k]) goto L_100; } /* Update the Pascal Triangle. */ p[n + 1] = 1.e0; for (k = n; k >= 1; k--) { p[k] += p[k - 1]; } } L_100: printf("%4ld%4ld%26.17e%26.17e%16.7e\n", n, k, tp, p[k], p[k] - tp); exit(0); } /* end of function */