#include #include #include "combinatoire.h" void usage (char *commande); int correspond (char *nom_fonction, int arite, char *argv[], int argc); int main (int argc, char *argv[]) { unsigned long r; if (correspond ("factorielle", 1, argv, argc)) r = cmb_factorielle (strtoul (argv[2], NULL, 10)); else if (correspond ("combinaison", 2, argv, argc)) r = cmb_combinaison (strtoul (argv[2], NULL, 10), strtoul (argv[3], NULL, 10)); else if (correspond ("arrangement", 2, argv, argc)) r = cmb_arrangement (strtoul (argv[2], NULL, 10), strtoul (argv[3], NULL, 10)); else if (correspond ("catalan", 1, argv, argc)) r = cmb_catalan (strtoul (argv[2], NULL, 10)); else usage (argv[0]); printf ("%ld", r); return EXIT_SUCCESS; } void usage (char *commande) { printf ("usage %s opération argument(s) \n" "opérations disponibles :\n" " factorielle n\n" " combinaison n p\n" " arrangement n p\n" " catalan n\n", commande); exit (EXIT_FAILURE); } int correspond (char *nom_fonction, int arite, char *argv[], int argc) { return argc == 2 + arite && !strcmp (argv[1], nom_fonction); }