double arrangement( int k, int n ) { double res = 0 ; res = factorielle(n)/factorielle( n-k ) ; return res ; }
/** * Renvoie le résultat de l'opération * * @author Serge COUDÉ * * @param char operateur Opérateur de l'opération * @param int ope1 Opérande 1 * @param int ope2 Opérande 2 * @return double Résultat de l'opération */ double calculeOperation(char operateur, int ope1, int ope2) { switch(operateur) { case '+': return ope1 + ope2; break; case '-': return ope1 - ope2; break; case 'x': return ope1 * ope2; break; case '/': return ope1 / ope2; break; case '^': return pow(ope1, ope2); break; case '!': return factorielle(ope1); break; default: return 0; break; } }
int factorielle(int n) { if (n == 0) { return 1; } else { return n * factorielle(n-1); } }
double combinaison( int k, int n ) { double res = 0 ; res = arrangement( k, n ) / factorielle( k ) ; return res ; }
//fonction factorielle int factorielle (int n) { int f; if (n <= 1) f = 1; else f = n * factorielle(--n); return f; }
int factorielle (int k){ int r = k; if (r==0){ r=1; } else if (r>0){ r=r*factorielle(r-1); } return r; }
/* calcule de la constante e approchee */ double e_approchee(int n) { int i; /* Var. de boucle */ double res = 0; /* elt neutre de l'addition */ for (i = 0; i <= n; i = i + 1) /* Pour i = 1, 2, ..., n */ { res = res + 1.0 / factorielle(i); /* attention on ne veut pas de division entiere */ } /* Valeur fonction */ return res; }
void init(tab cmd){ if (!strcmp(cmd, "addition")) { int a,b; printf("Enter two integers :\n"); scanf("%d %d", &a, &b); printf("%d + %d = %d \n", a, b, addition(a, b)); } else if (!strcmp(cmd, "pgcd")) { int a,b; printf("Enter two integers :\n"); scanf("%d %d", &a, &b); printf("pgcd (%d, %d) = %d \n", a, b, pgcd(a, b)); } else if (!strcmp(cmd, "somme")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); printf("Somme des %d premiers entiers = %d \n", a, somme(a)); } else if (!strcmp(cmd, "factorielle")) { int a; printf("Enter one integers :\n"); scanf("%d", &a); printf("(%d)! = %d \n", a, factorielle(a)); } else if (!strcmp(cmd, "puissance")) { float a,b; printf("Enter two floats :\n"); scanf("%f %f", &a, &b); printf("(%g ^ %g) = %g \n", a, b, puissance(a, b)); } else if (!strcmp(cmd, "isocele")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); isocele(a); } else if (!strcmp(cmd, "cercle")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); cercle(a); } else { printf("Command not found \n"); printf("Running listAll ... ? \n"); } return ; }
int main() { int x = -3; int y = 5; int z; /* Un calcul sans signification particulière */ x = valeur_absolue(x); /* valeur absolue de x */ z = minimum(x, y); /* minimum entre x et y */ z = factorielle(z); /* z! */ z = minimum(y, z); /* minimum entre y et z */ /* Valeur fonction */ return EXIT_SUCCESS; }
//fonction principale int main(){ int a, b; srand(time(NULL)); a = rand() % 8 + 2; b = factorielle(a); printf("\nFactorielle de %d vaut %d\n\n", a, b); a = rand() % 100; b = somme(a); printf("\nLa somme des entiers de 1 a %d vaut %d\n\n", a, b); a = rand() % 100; b = rand() % 100; printf("\nLe maximum entre %d et %d vaut %d\n\n", a, b, maximum(a,b)); return 0; }
long int factorielle(long int n) { if(n <= 1) return 1 ; return n * factorielle(n-1) ; }
Entier& Entier::fact() { Entier* res = new Entier(factorielle(mX)); Entier& ref = *res; return ref; }