- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- int t[10]={0,0,0,0,0,0,0,0,0,0,};
- struct Poly{
- float coef;
- int exp;
- struct Poly *suiv;
- };
-
- struct Poly *Init(struct Poly **tete)
- {
- *tete=NULL;
- return *tete;
- }
-
- struct Poly *Ins(struct Poly **tete,int x,float y)
- {
-
- struct Poly *p;
- struct Poly *tempo1;
- tempo1=*tete;
- if(*tete==NULL) // si la liste est vide
- {
- p=(struct Poly *)malloc(sizeof(struct Poly*));
- p->exp=x;
- t[x]=y+t[x];
- p->coef=y;
- p->suiv=*tete;
- *tete=p;
- }
- else
- {
- if(x<tempo1->exp)
- {
- p=(struct Poly*)malloc(sizeof(struct Poly*));
- p->exp=x;
- t[x]=y+t[x];
- p->coef=y;
- p->suiv=*tete;
- *tete=p;
- }
- else
- {struct Poly*tempo;
- p=*tete;
- tempo=*tete;
- while((x>p->exp) && (p)) //fait Ins milieu et fin
- {
- tempo=p; //pour sauver le noeud précedent == chaînage double
- p=p->suiv;
- }
- p=(struct Poly*)malloc(sizeof(struct Poly*));
- p->exp=x;
- t[x]=y+t[x];
- p->coef=y;
- p->suiv=tempo->suiv;
- tempo->suiv=p;
- }
- }
- return *tete;
- }
-
- Saisie_ins(struct Poly **tete)
- {
- short rep;
- float coef;
- int exp;
- do
- {
- printf("Coef=");scanf("%f",&coef);
- if(coef!=0)
- {
- printf("Expo=");scanf("%d",&exp);
- Ins(tete,exp,coef);
- }
-
- printf("Continuez ? 0/1 ");
- scanf("%d",&rep);
-
- }
- while(rep==1);
-
- }
-
- void Aff_recu(struct Poly* tete) // fonction recursive;
- {
- if(tete) //tant que (l!=NULL),on fait appel à Aff_recu(tete);
- {
- printf("%.2f %d\n",tete->coef,tete->exp);
- Aff_recu(tete->suiv);
- }
- }
-
- void main()
- {
- struct Poly *tete,*tete1,*tete2;
- int i;
-
- clrscr();
- printf("\n\n*************** Polyn“me A ***************\n\n");
-
- Init(&tete);
- Saisie_ins(&tete);
- printf("\n\nCoef Exp\n\n");
- Aff_recu(tete);
-
- printf("\n\n*************** Polyn“me B ***************\n\n");
-
- Init(&tete1);
- Saisie_ins(&tete1);
- printf("\n\nCoef Exp\n\n");
- Aff_recu(tete1);
-
- printf("\n\n*************** Polyn“me Somme ***************\n\n");
-
- Init(&tete2);
- for(i=0;i<10;i++)
- if(t[i]!=0)
- Ins(&tete2,i,t[i]);
- printf("\n\nCoef Exp\n\n");
- Aff_recu(tete2);
- getch();
- }
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int t[10]={0,0,0,0,0,0,0,0,0,0,};
struct Poly{
float coef;
int exp;
struct Poly *suiv;
};
struct Poly *Init(struct Poly **tete)
{
*tete=NULL;
return *tete;
}
struct Poly *Ins(struct Poly **tete,int x,float y)
{
struct Poly *p;
struct Poly *tempo1;
tempo1=*tete;
if(*tete==NULL) // si la liste est vide
{
p=(struct Poly *)malloc(sizeof(struct Poly*));
p->exp=x;
t[x]=y+t[x];
p->coef=y;
p->suiv=*tete;
*tete=p;
}
else
{
if(x<tempo1->exp)
{
p=(struct Poly*)malloc(sizeof(struct Poly*));
p->exp=x;
t[x]=y+t[x];
p->coef=y;
p->suiv=*tete;
*tete=p;
}
else
{struct Poly*tempo;
p=*tete;
tempo=*tete;
while((x>p->exp) && (p)) //fait Ins milieu et fin
{
tempo=p; //pour sauver le noeud précedent == chaînage double
p=p->suiv;
}
p=(struct Poly*)malloc(sizeof(struct Poly*));
p->exp=x;
t[x]=y+t[x];
p->coef=y;
p->suiv=tempo->suiv;
tempo->suiv=p;
}
}
return *tete;
}
Saisie_ins(struct Poly **tete)
{
short rep;
float coef;
int exp;
do
{
printf("Coef=");scanf("%f",&coef);
if(coef!=0)
{
printf("Expo=");scanf("%d",&exp);
Ins(tete,exp,coef);
}
printf("Continuez ? 0/1 ");
scanf("%d",&rep);
}
while(rep==1);
}
void Aff_recu(struct Poly* tete) // fonction recursive;
{
if(tete) //tant que (l!=NULL),on fait appel à Aff_recu(tete);
{
printf("%.2f %d\n",tete->coef,tete->exp);
Aff_recu(tete->suiv);
}
}
void main()
{
struct Poly *tete,*tete1,*tete2;
int i;
clrscr();
printf("\n\n*************** Polyn“me A ***************\n\n");
Init(&tete);
Saisie_ins(&tete);
printf("\n\nCoef Exp\n\n");
Aff_recu(tete);
printf("\n\n*************** Polyn“me B ***************\n\n");
Init(&tete1);
Saisie_ins(&tete1);
printf("\n\nCoef Exp\n\n");
Aff_recu(tete1);
printf("\n\n*************** Polyn“me Somme ***************\n\n");
Init(&tete2);
for(i=0;i<10;i++)
if(t[i]!=0)
Ins(&tete2,i,t[i]);
printf("\n\nCoef Exp\n\n");
Aff_recu(tete2);
getch();
}