// Compiler : gcc eratosthene.c -o eratosthene -lm // Executer : ./eratosthene #include #include #include #define TAILLE 30 void initialiserTableau(int tableau[], int taille) { tableau[0] = 0; tableau[1] = 0; for(int i = 2 ; i < taille ; i++ ) { tableau[i] = 1; } } void afficherLesNombresPremiers(int tableau[], int taille) { for(int i = 0 ; i < taille ; i++ ) { if( tableau[i] == 1 ) { printf("%d ", i); } } printf("\n"); } void eratosthene(int tableau[], int taille) { for(int i = 2 ; i < sqrt(taille) ; i++) { if(tableau[i] == 1) { for(int multiple = 2*i; multiple < taille ; multiple+=i) { tableau[multiple] = 0; } } } } void main(void) { int tableau[TAILLE]; initialiserTableau(tableau, TAILLE); eratosthene(tableau, TAILLE); afficherLesNombresPremiers(tableau, TAILLE); }