#include #include #include #include #include "premiers.h" #define NOMBRES_PAR_LIGNE 10 static void usage(char * nom_commande) { fprintf(stderr, "Usage : %s \n", nom_commande); } static bool ligne_complete(int i) { return ((i+1) % NOMBRES_PAR_LIGNE == 0); } int main(int argc, char * argv[]) { if (argc != 2) { usage(argv[0]); return EXIT_FAILURE; } int n = atoi(argv[1]); int longueur_n = ceil(log10(n)); int * premiers; int npremiers = premiers_inferieurs(n, &premiers); int i; for (i = 0; i < npremiers; i++) { printf("%*d ", longueur_n, premiers[i]); if (ligne_complete(i)) { printf("\n"); } } if (! ligne_complete(i)) { printf("\n"); } free(premiers); return EXIT_SUCCESS; }