Yasmtidk / practice

practice INF155
0 stars 0 forks source link

Exercice 14 #30

Open Yasmtidk opened 5 months ago

Yasmtidk commented 5 months ago

include

include

include

define MAX_LANCER 100000

int nb_aleatoire(int min, int max);

int main() { int nombre; int compteur_7 = 0; int compteur = 0; float moyenne;

srand((unsigned int) time(NULL));
rand();

while(compteur < MAX_LANCER)
{
    compteur++;

    nombre = nb_aleatoire(1,6) + nb_aleatoire(1,6);
    if(nombre == 7)
    {
        compteur_7++;
    }
}

moyenne = (float)compteur_7 / (float)compteur;

printf("La probabilite d'obtenir 7 est de : %.2f", moyenne);

return EXIT_SUCCESS;

}

int nb_aleatoire(int min, int max) { return min + (int)(rand()/(RAND_MAX + 0.001) * (max - min + 1)); }