Above program takes input of coefficient and power separately of 2 different polynomials add them up to a new polynomial.It is successfully compiled and executed in DEV CPP as C file.It Turbo C compiler add void before main function to avoid warning messages.

Nice Logic appiled Behind This Snippet
``````#include<stdio.h>
#include<malloc.h>
#include<conio.h>
int coeff;
int pow;
};
{
char ch;
do
{
printf("\n enter coeff:");
scanf("%d",&node->coeff);
printf("\n enter power:");
scanf("%d",&node->pow);
node=node->next;
node->next=NULL;
printf("\n continue(y/n):");
ch=getch();
}
while(ch=='y' || ch=='Y');
}
{
while(node->next!=NULL)
{
printf("%dx^%d",node->coeff,node->pow);
node=node->next;
if(node->next!=NULL)
printf("+");
}
}
{
while(poly1->next &&  poly2->next)
{
if(poly1->pow>poly2->pow)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
else if(poly1->pow<poly2->pow)
{
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}
else
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff+poly2->coeff;
poly1=poly1->next;
poly2=poly2->next;
}
poly=poly->next;
poly->next=NULL;
}
while(poly1->next || poly2->next)
{
if(poly1->next)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
if(poly2->next)
{
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}
poly=poly->next;
poly->next=NULL;
}
}
main()
{
char ch;
do{
printf("\nenter 1st number:");
create(poly1);
printf("\nenter 2nd number:");
create(poly2);
printf("\n1st Number:");
show(poly1);
printf("\n2nd Number:");
show(poly2);
show(poly);
ch=getch();
}
while(ch=='y' || ch=='Y');
}``````

Hello,
this program will run successfully no doubt,but USER should enter the polynomials in ascending order only. This Program will not give Proper answer for DESCENDING order or any order that user might enter.........

Hi,
This program is not working when we enter the polynomials in an unsorted order...

``````#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int coef;
int pow;
struct node *next;
}poly;
{
int ch;
system("clear");
printf("\n\t1)Create 1'st Polynomial ");
printf("\n\t2)Create 2'nd Polynomial ");
printf("\n\t3)Display");
scanf("%d",&ch);
return ch;
}
{
poly *t1,*temp;
int i,flag=1,scan;
t1=(poly *)malloc(sizeof(poly));
temp=(poly *)malloc(sizeof(poly));
for(scan=1;flag==1;scan++)
{
flag=0;
{
if(temp->pow<temp->next->pow)
{
t1->coef=temp->coef;
t1->pow=temp->pow;

temp->coef=temp->next->coef;
temp->pow=temp->next->pow;

temp->next->coef=t1->coef;
temp->next->pow=t1->pow;

flag=1;
}
temp=temp->next;
}
}
}
{
int coef,pow;
printf("\n\tEnter number of terms: ");
int i;
poly *newnode;
{
newnode=(poly *)malloc(sizeof(poly));
system("clear");
printf("\n\tEnter %d term: ",i+1);
scanf("%d",&coef);
printf("\n\tEnter power of %d term: ",i+1);
scanf("%d",&pow);
newnode->coef=coef;
newnode->pow=pow;
while(curr->next)
curr=curr->next;
curr->next=newnode;
curr=newnode;
}
curr->next=NULL;
}
{
printf("\n\tEmpty\n");
else
{
while(temp)
{
if(temp->next==NULL)
{
if(temp->pow==0)
{
printf("%d",temp->coef);
return;
}
if(temp->pow==1)
{
printf("%dx",temp->coef);
return;
}
else
{
printf("%dx^%d",temp->coef,temp->pow);
return;
}
}
else
if(temp->pow==1)
printf("%dx+",temp->coef);
else
if(temp->pow==0)
printf("%d+",temp->coef);
else
printf("%dx^%d+",temp->coef,temp->pow);
temp=temp->next;
}
}
}
{
printf("\n\tEmpty\n");
else
{
while(temp)
{
if(temp->next==NULL)
{
if(temp->pow==0)
{
printf("%d",temp->coef);
return;
}
if(temp->pow==1)
{
printf("%dx",temp->coef);
return;
}
else
{
printf("%dx^%d",temp->coef,temp->pow);
return;
}
}
else
if(temp->pow==1)
printf("%dx+",temp->coef);
else
if(temp->pow==0)
printf("%d+",temp->coef);
else
printf("%dx^%d+",temp->coef,temp->pow);
temp=temp->next;
}
}
}
{
poly *curr1,*curr2,*curr3;
poly *newnode;
while(curr1||curr2)
{
newnode=(poly *)malloc(sizeof(poly));
newnode->next=NULL;
if(curr1->pow>curr2->pow)
{
newnode->coef=curr1->coef;
newnode->pow=curr1->pow;
curr1=curr1->next;
}
else
if(curr1->pow<curr2->pow)
{
newnode->coef=curr2->coef;
newnode->pow=curr2->pow;
curr2=curr2->next;
}
else
{
newnode->coef=curr1->coef+curr2->coef;
newnode->pow=curr2->pow;
curr1=curr1->next;
curr2=curr2->next;
}
if(curr1==NULL&&curr2!=NULL)
{
newnode->coef=curr2->coef;
newnode->pow=curr2->pow;
curr2=curr2->next;
}
if(curr2==NULL&&curr1!=NULL)
{
newnode->coef=curr1->coef;
newnode->pow=curr1->pow;
curr1=curr1->next;
}
curr3->next=newnode;
curr3=newnode;
curr3->next=NULL;
}
}
main()
{
int ch;
{
if(ch==1)
else
if(ch==2)
else
if(ch==3)
{
printf("\n\t1'st Polynomial\t\t");
printf("\n");
printf("\n\t2'nd Polynomial\t\t");
getchar();getchar();
}
else
if(ch==4)
{
printf("\n\tResult\t\t");