#include #include #include bool* creerTableauBooleensEquiprobables(int n) { bool* t = (bool*) calloc(n, sizeof(bool)); if (t != NULL) { for (int i = 0; i < n; i++) { if (rand() % 2 == 0) { t[i] = true; } } } return t; } int calculerNombreCouplesDeVraiConsecutifs(bool* t, int n) { if (t == NULL) { return 0; } int cpt = 0; for (int i = 0; i < n - 1; i++) { if (t[i] && t[i + 1]) { cpt++; } } return cpt; } void main(void) { srand(10); int n = 50000; bool* tb = creerTableauBooleensEquiprobables(n); if (tb != NULL) { printf("%d couples de vrai consecutifs\n", calculerNombreCouplesDeVraiConsecutifs(tb, n)); } if (tb != NULL) { free(tb); tb = NULL; } }