home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- * CH06_03.C Fonctions: *
- * Calcul de C( n, m) avec des nombres rΘels *
- *********************************************************************/
-
- #include<stdio.h>
-
- #define MAX_lf 1.79e308
-
- void LitInt( int*);
- int Combinaisons( int, int, double*);
-
- main( void)
- {
- double cnm0;
- int n0, m0, test;
-
- do
- {
- printf(" Entrez n= ");
- LitInt( &n0);
-
- printf(" Entrez m= ");
- LitInt( &m0);
-
- test= Combinaisons( n0, m0, &cnm0);
-
- if( test== -1)
- printf(" Erreur dans les paramΦtres!\n");
-
- if( test== 1)
- printf(" Sortie du domaine des doubles!\n");
- }
- while( test);
-
- printf(" C( %d, %d)= %.0lf", n0, m0, cnm0);
- }
-
- int Combinaisons( int n, int m, double* c)
- {
- double cnm = 1;
- int i, f;
-
- if( n< 0 || m< 0 || m> n) return -1;
-
- if ( m* 2 > n) m= n- m;
- for (i= 1 ; i <= m; n--, i++)
- {
- if ((f= n) % i == 0)
- f /= i;
- else cnm /= i;
- if( MAX_lf/ f< cnm) return 1;
- cnm *= f;
- }
- *c= cnm;
- return 0;
- }
-
- void LitInt( int* Entier)
- {
- while( scanf("%d", Entier) != 1)
- while( getchar() != '\n' );
- while( getchar() != '\n' );
- }
-