Bien programmer en langage C
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le deal à ne pas rater :
Funko POP! Jumbo One Piece Kaido Dragon Form : où l’acheter ?
Voir le deal

besoin d'aide gestion de polynome

2 participants

Aller en bas

besoin d'aide gestion de polynome Empty besoin d'aide gestion de polynome

Message  patricia Dim 15 Fév 2009 - 19:28

en fait j'ai considérablement avancer, ma fonction création marche à moitié, quand je crée et que je sors de l'exécution et que j'appelle la fonction affichage il n'y a rien qui s'affiche. on dirait que la création ne se fait pas vraiment, aidez moi svp; j"en ai grand besoin. j"ai vraiment besoin d'aide, voici mon code:
Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>

typedef struct
  {
    float coef;
    int deg;
    int suiv;
  }terme;


// Fonction qui crée les polynômes
void creation()
  {

    char nom[10],nompoly[10][10];
    int i,j,indice=0,prec,deg, repons;
    float coeff,tempo;
    terme poly [10][21];

    printf(" \n entrez le nom que vous donnez au polynome:");
    fflush(stdin);
    gets(nom);
   
    i=0;
    while (i<indice)
    {
      while (strcmp(nom,nompoly[i])==0)
      {
       printf("ce nom est déja utilisé");
        printf("donnez un autre nom");
       fflush(stdin);
       gets(nom);
      }
      i++;
    }
    strcpy(nompoly[i],nom);
    poly[indice][0].deg=0;
    poly[indice][0].coef=0;
    prec=0;
    poly[indice][0].suiv=1;
    i=1;  j=1;
    repons=1;
 
 while (repons=1)
 { 
    do
    {
      printf("entrez le coefficient  coeff<>0 :");
      scanf("%f",&coeff);
      printf("entrez le degre  ok :");
      scanf("%d",&deg);
       if (deg!=poly[indice][prec].deg)
         {
           poly[indice][i].coef=coeff;
           poly[indice][i].deg=deg;
            poly[indice][i].suiv=i+1;
           prec=i;
           i++;
         }

       else
         poly[indice][prec].coef=poly[indice][prec].coef + coeff;
         j++;
     

      poly[indice][i-1].suiv=0;
      poly[indice][0].coef=i;
      indice++;
     
        printf("ya til encore un autre terme a entrer: ");
        printf("tapez  1:oui  0:non  ");
        scanf("%d",repons);
  }
  while ( i<10);
}

}
 

// Fonction qui affiche la liste de tous les polynômes existant
void affichage()
{
    int i,j,indice;
    char nom[10];
    terme poly [10][21];
   
    for (j=0;j<indice;j++)
      {
          i=0;
          printf("%s=",nom[j]);
          do
            {
             if(i!=0) printf("+");
             i=poly[j][i].suiv;
             printf("%.2f",poly[j][i].coef);
             if (poly[j][i].deg!=0)
                  {
                      printf("x");
                  printf("%d",poly[j][i].deg);
                  }
          }while(poly[j][i].suiv!=0);
          printf("\n\n");
      }
      getch();
}                    

// Gestion d'un polynôme

void gestion()
{
  char poly; int choix;
  printf("\n entrez le polynôme que vous voulez gerer:");
  scanf("%s",poly);

printf("\n--------------- Menu ---------------");
printf("\n      Gestion d'un polynôme        ");
printf("\n    1- Ajouter un terme            ");
printf("\n    2- Supprimer un terme          ");
printf("\n    3- Afficher le polynôme        ");
printf("\n    4- Chercher un terme            ");
printf("\n    5- Réorganiser                  ");
printf("\n    6- Le terme le plus grand      ");
printf("\n    7- Le terme le plus petit      ");
printf("\n    8- Evaluer P(x) pour un x donné ");
printf("\n    9- Dérivé d'un polynôme        ");
printf("\n  10- Quitter                      ");
printf("\n------------------------------------");

printf("entrez le nouveau choix:");
       scanf("%d",&choix);
       switch (choix)
       {
         case 1:
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
         case 7:
         case 8:
         case 9:
         case 10:
         default: puts("choix invalide");
       }
      
       getch();
}



 main()
{

    char nom[10],tabnom[10][10],ch,rep;
    int i,prec,deg,prod,j,choix,premier;
    terme poly[10][21];

  printf(" \n MENU PRINCIPAL");
  printf(" \n³1: CREER UN POlYNOME                ³");
  printf(" \n³2: AFFICHER LA LISTE DES POLYNOMES  ³");
  printf(" \n³3: GESTION D'UN POLYNOME            ³");
  printf(" \n³4: SUPPRIMER UN POLYNOME            ³");
  printf(" \n³5: SOMME DE DEUX POLYNOME          ³");
  printf(" \n³0: QUITTER                          ³");
  printf(" \n³                  Votre choix :    ³");
 


  printf("Entrez votre choix:");
    scanf("%d",&choix);

  switch (choix)
  {
    case 1: {  creation();  break;  }
    case 2: {  affichage();  break;  }
    case 3: {  gestion();    }
  }



  getch();


}


Dernière édition par -ed- le Lun 16 Fév 2009 - 20:25, édité 1 fois (Raison : Merci d'utiliser les balises de code. [code]mon code ici ... [/code])

patricia

Messages : 3
Date d'inscription : 12/02/2009

Revenir en haut Aller en bas

besoin d'aide gestion de polynome Empty Re: besoin d'aide gestion de polynome

Message  -ed- Lun 16 Fév 2009 - 20:31

patricia a écrit:en fait j'ai considérablement avancer, ma fonction création marche à moitié, quand je crée et que je sors de l'exécution et que j'appelle la fonction affichage il n'y a rien qui s'affiche. on dirait que la création ne se fait pas vraiment, aidez moi svp; j"en ai grand besoin. j"ai vraiment besoin d'aide, voici mon code:
Il y a pas mal de choses à corriger avant d'aller plus loin :
Code:


-------------- Build: Debug in hello ---------------

Compiling: main.c
Linking console executable: bin\Debug\hello.exe
C:\dev\hello\main.c:16: warning: function declaration isn't a prototype
C:\dev\hello\main.c: In function `creation':
C:\dev\hello\main.c:47: warning: suggest parentheses around assignment used as truth value
C:\dev\hello\main.c:75: warning: format argument is not a pointer (arg 2)
C:\dev\hello\main.c:20: warning: unused variable `tempo'
C:\dev\hello\main.c:30: warning: will never be executed
C:\dev\hello\main.c:30: warning: will never be executed
C:\dev\hello\main.c:30: warning: will never be executed
C:\dev\hello\main.c: At top level:
C:\dev\hello\main.c:85: warning: function declaration isn't a prototype
C:\dev\hello\main.c: In function `affichage':
C:\dev\hello\main.c:93: warning: format argument is not a pointer (arg 2)
C:\dev\hello\main.c:86: warning: 'indice' might be used uninitialized in this function
C:\dev\hello\main.c: At top level:
C:\dev\hello\main.c:113: warning: function declaration isn't a prototype
C:\dev\hello\main.c: In function `gestion':
C:\dev\hello\main.c:116: warning: format argument is not a pointer (arg 2)
C:\dev\hello\main.c:114: warning: 'poly' might be used uninitialized in this function
C:\dev\hello\main.c: At top level:
C:\dev\hello\main.c:155: warning: return type defaults to `int'
C:\dev\hello\main.c:155: warning: function declaration isn't a prototype
C:\dev\hello\main.c: In function `main':
C:\dev\hello\main.c:157: warning: unused variable `nom'
C:\dev\hello\main.c:157: warning: unused variable `tabnom'
C:\dev\hello\main.c:157: warning: unused variable `ch'
C:\dev\hello\main.c:157: warning: unused variable `rep'
C:\dev\hello\main.c:158: warning: unused variable `i'
C:\dev\hello\main.c:158: warning: unused variable `prec'
C:\dev\hello\main.c:158: warning: unused variable `deg'
C:\dev\hello\main.c:158: warning: unused variable `prod'
C:\dev\hello\main.c:158: warning: unused variable `j'
C:\dev\hello\main.c:158: warning: unused variable `premier'
C:\dev\hello\main.c:159: warning: unused variable `poly'
C:\dev\hello\main.c:187: warning: control reaches end of non-void function
Output size is 24.44 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 27 warnings
Vues les conditions d'entrée, on entre jamais dans cette boucle :
Code:

  int i, j, indice = 0, prec, deg, repons;
  i = 0;
  while (i < indice)
  {
      i++;
  }
Il y a plein d'erreurs grossières dans ton code (lecture de variables non initialisées, confusion entre chaine de caractères et char etc. Je ne comprend pas du tout ce que tu veux faire...
-ed-
-ed-
Admin
Admin

Messages : 290
Date d'inscription : 26/05/2008
Age : 67
Localisation : Paris 14eme arrondissement (75, France)

http://bien-programmer.fr

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum
Ne ratez plus aucun deal !
Abonnez-vous pour recevoir par notification une sélection des meilleurs deals chaque jour.
IgnorerAutoriser