00001 #ifndef synaps_arithm_binomial_h 00002 #define synaps_arithm_binomial_h 00003 00004 #include <synaps/init.h> 00005 00006 __BEGIN_NAMESPACE_SYNAPS 00007 00009 template <typename T> T binomial(int n, int p) 00010 { 00011 T n1=1; 00012 00013 if(p!=0) 00014 { 00015 if((n-p)<p) p=n-p; 00016 int n2=n; 00017 for(int i=1;i<=p;i++,n2--) n1=n1*n2/T(i); 00018 } 00019 00020 return(n1); 00021 } 00022 00023 __END_NAMESPACE_SYNAPS 00024 00025 #endif // synaps_arithm_binomial_h 00026