struct node *insert(struct node *p);
void *add (struct node *a,struct node *b);
#include<stdio. h>
#include<conio. h>
#include<alloc. h>
struct node
{
int cof,ex,ey,ez;
struct node *link;
};
void main ()
{
struct node *a,*b,*q;
int i,ter1,ter2;
clrscr();
printf("\n\nNo of terms you want to enter for first polynomial");
scanf("%d",&ter 1);
printf("\n\nNo of terms you want to enter for second polynomial");
scanf("%d",&ter 2);
a=NULL;
b=NULL;
for(i=0;i<ter1; i++)
{
a=insert(a);
}
for(i=0;i<ter2; i++)
{
b=insert(b);
}
printf("\n\nFor first polynomial");
q=a;
for(i=0;i<ter1; i++)
{
printf("\n\nEnt er the coffecient & exponent of x,y,z of %d term :",i+1);
scanf("%d%d%d%d ",&q->cof,&q->ex,&q->ey,&q->ez);
q=q->link;
}
printf("\n\nFor second polynomial");
q=b;
for(i=0;i<ter2; i++)
{
printf("\n\nEnt er the coffecient & exponent of x,y,z of %d term :",i+1);
scanf("%d%d%d%d ",&q->cof,&q->ex,&q->ey,&q->ez);
q=q->link;
}
printf("\n\nFir st polynomial is :\n\n");
q=a;
for(i=0;i<ter1; i++)
{
printf("%d(X^%d Y^%dZ^%d) + ",q->cof,q->ex,q->ey,q->ez);
q=q->link;
}
printf("\n\nSec ond polynomial is :\n\n");
q=b;
for(i=0;i<ter2; i++)
{
printf("%d(X^%d Y^%dZ^%d) + ",q->cof,q->ex,q->ey,q->ez);
q=q->link;
}
add(a,b);
getch();
}
struct node *insert(struct node *p)
{
struct node *temp;
if(p==NULL)
{
temp=(struct node*)malloc(si zeof(struct node));
p=temp;
temp->link=NULL;
}
else
{
temp=p;
temp->link=(struct node*)malloc(si zeof(struct node));
temp=temp->link;
temp->link=NULL;
}
return(p);
}
void *add(struct node *a,struct node *b)
{
struct node *q,*p,*c,*temp;
int i=0,j;
p=a;
q=b;
c=NULL;
while(p->link!=NULL && q->link!=NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
p=p->link;
q=q->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
c=insert(c);
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
}
}
if(p->link==NULL && q->link!=NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=insert(c) ;
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
q=q->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=insert(c) ;
temp=temp->link;
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
c=insert(c);
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
q=q->link;
}
do
{
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+1;
q=q->link;
}while(q->link!=NULL);
}
if(q->link==NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
p=p->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
p=p->link;
}
do
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
i=i+1;
}while(p->link!=NULL);
}
printf("\n\n");
temp=c;
for(j=0;j<i;j++ )
{
printf("%d(X^%d Y^%dZ^%d)+",tem p->cof,temp->ex,temp->ey,temp->ez);
temp=temp->link;
}
}
Help me to solve this question
void *add (struct node *a,struct node *b);
#include<stdio. h>
#include<conio. h>
#include<alloc. h>
struct node
{
int cof,ex,ey,ez;
struct node *link;
};
void main ()
{
struct node *a,*b,*q;
int i,ter1,ter2;
clrscr();
printf("\n\nNo of terms you want to enter for first polynomial");
scanf("%d",&ter 1);
printf("\n\nNo of terms you want to enter for second polynomial");
scanf("%d",&ter 2);
a=NULL;
b=NULL;
for(i=0;i<ter1; i++)
{
a=insert(a);
}
for(i=0;i<ter2; i++)
{
b=insert(b);
}
printf("\n\nFor first polynomial");
q=a;
for(i=0;i<ter1; i++)
{
printf("\n\nEnt er the coffecient & exponent of x,y,z of %d term :",i+1);
scanf("%d%d%d%d ",&q->cof,&q->ex,&q->ey,&q->ez);
q=q->link;
}
printf("\n\nFor second polynomial");
q=b;
for(i=0;i<ter2; i++)
{
printf("\n\nEnt er the coffecient & exponent of x,y,z of %d term :",i+1);
scanf("%d%d%d%d ",&q->cof,&q->ex,&q->ey,&q->ez);
q=q->link;
}
printf("\n\nFir st polynomial is :\n\n");
q=a;
for(i=0;i<ter1; i++)
{
printf("%d(X^%d Y^%dZ^%d) + ",q->cof,q->ex,q->ey,q->ez);
q=q->link;
}
printf("\n\nSec ond polynomial is :\n\n");
q=b;
for(i=0;i<ter2; i++)
{
printf("%d(X^%d Y^%dZ^%d) + ",q->cof,q->ex,q->ey,q->ez);
q=q->link;
}
add(a,b);
getch();
}
struct node *insert(struct node *p)
{
struct node *temp;
if(p==NULL)
{
temp=(struct node*)malloc(si zeof(struct node));
p=temp;
temp->link=NULL;
}
else
{
temp=p;
temp->link=(struct node*)malloc(si zeof(struct node));
temp=temp->link;
temp->link=NULL;
}
return(p);
}
void *add(struct node *a,struct node *b)
{
struct node *q,*p,*c,*temp;
int i=0,j;
p=a;
q=b;
c=NULL;
while(p->link!=NULL && q->link!=NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
p=p->link;
q=q->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
c=insert(c);
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
}
}
if(p->link==NULL && q->link!=NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=insert(c) ;
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
q=q->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=insert(c) ;
temp=temp->link;
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
c=insert(c);
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
q=q->link;
}
do
{
temp->link=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+1;
q=q->link;
}while(q->link!=NULL);
}
if(q->link==NULL)
{
if(p->ex==q->ex && p->ey==q->ey && p->ez==q->ez)
{
c=insert(c) ;
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof + q->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
temp->link=NULL;
i=i+1;
p=p->link;
}
else
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=q->cof;
temp->ex=q->ex;
temp->ey=q->ey;
temp->ez=q->ez;
i=i+2;
p=p->link;
}
do
{
c=insert(c);
temp=c;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->cof=p->cof;
temp->ex=p->ex;
temp->ey=p->ey;
temp->ez=p->ez;
i=i+1;
}while(p->link!=NULL);
}
printf("\n\n");
temp=c;
for(j=0;j<i;j++ )
{
printf("%d(X^%d Y^%dZ^%d)+",tem p->cof,temp->ex,temp->ey,temp->ez);
temp=temp->link;
}
}
Help me to solve this question
Comment