Goldberg Profil : Jeune recrue | J'ai ces deux warning qui apparaissent...d'où viennent-ils?
I:\C\bin>gcc --std=c99 -Wall -W --pedantic maite.c -o maite.exe
maite.c: In function `Estpremier':
maite.c:68: warning: control reaches end of non-void function
maite.c: In function `main':
maite.c:125: warning: int format, different type arg (arg 2)
Code :
- /**
- * Solution for the exercise number 4 : Decomposition.
- * This code is ISO-C99 compliant.
- **/
- #include <stdio.h>
- void PrintDescription(void)
-
- /**
- * Affiche des informations concernant la fonction decomposition
- * sur la sortie standard.
- **/
-
- {
- printf("\n" );
-
- printf( "******************************************************\n" );
-
- printf( "* Decomposition by Vincent Roloux : *\n" );
-
- printf( "******************************************************\n" );
-
- printf( "* This method allows to obtain the decomposition *\n" );
-
- printf( "* on prime factors of a number between 2 and n. *\n" );
-
- printf( "******************************************************\n" );
-
- }
- int Estpremier(int b)
- /**
- * Fonction qui retourne la valeur entree si et seulement si
- * cette valeur (b) est premiere, dans le cas contraire la
- * fonction teste la valeur suivante (b+1), etc
- **/
-
- {
- int i,r,a;
-
- if (b==1)
- a=0; // 1 n'est pas premier
- else if (b==2)
- a=2; // 2 est premier
- else {
- i=2;
- r=b%i; // on divise b par toutes les valeurs
- while (r!=0 && i*i<b) { // i comprises entre 2 et la racine
- i++; // carree de b
- r=b%i;
- }
- if (r==0)
- a=0; // si le reste==0, b n'est pas premier
- else
- a=b; // si reste!=0, b est premier
- }
-
- if (a!=0)
- return a; // on retourne a si b est premier
- else
- b++; // autrement on augmente la valeur de b
- // d'une unité
- }
- void decomposition(int n)
- /**
- * Fonction qui divise le nombre n par des valeurs premieres (retournees
- * par la fonction Estpremier) : on regarde combien de fois la valeur
- * première divise n, qd la division n'est plus possible, on passe
- * a la valeur b suivante.
- **/
- {
- int b,value,j;
-
- for(b=2;b<=n;b++) {
- j=0;
-
- value=Estpremier(b); // on donne a value la valeur retournee
- // par la fonction Estpremier
- while (n%Estpremier(b)==0) { // on divise n par cette valeur
- n=n/Estpremier(b);
- j++ ; // a chaque fois que l'on a pu diviser
- } // n par la valeur, on augmente j de
- // 1 unite
- if (j!=0) {
- if (j==1)
- printf("%d",Estpremier(b)); // si le nbre entre est premier
- else
- printf("%d^%d",Estpremier(b),j); // on affiche value ^ j
- if (n!=1)
- printf("*" ); // si n!=1 on affiche le * et on
- } // passe au b suivant
-
- }
-
- printf("\n" );
- }
- int main(void)
- {
- int n, a;
-
- char choix;
-
- PrintDescription();
-
- while (1) {
- printf("\nEnter 1 if you want to perform the decomposition." );
- printf("\nEnter 2 if you want to exit.\n" );
- printf("\nYour choice = ? " ); // Ns proposons deux choix
- // 1) decomposition
- // 2) sortir du programme
- a = scanf("%d", &choix);
- if (a != 1) {
- printf("\nVous n'avez pas rentre un nombre !\n" ); // Si la valeur est
- return -1; // un caractère
- }
- else if ((choix!=1) & (choix!=2)) {
- printf("\nIntroduce 1 or 2 please\n" );
- };
- switch(choix) {
-
- case 1 :
- do {
- printf("\nEnter the number n :\n" );
- scanf("%d",&n);
- if (n<2) {
- printf("\nWhat is the interest to decompose on prime factors a number <2?" );
- }
- else
- printf("\nThe decompostion of %d on prime factors is :\n",n);
- decomposition(n);
- do {
- printf("\n\nDo you want to try again?\n" );
- printf("\nPress y if yes or n if no :\n" );
- scanf(" %c",&choix);
- } while (choix!='y' && choix!='n' && choix!='N' && choix!='Y');
- } while (choix!='n'&& choix!='N');
-
- case 2 :
- printf("\n" );
- printf("Good bye, have a nice day.\n" );
- return 0;
- }
- }
- }
|
|