ADDITON OF TWO POLYNOMIAL

442

 

BCA Third Semester

ADDITON OF TWO POLYNOMIAL

datastructure

#include<stdio.h>
#include<malloc.h>
#include<conio.h>
struct link{
int coeff;
int pow;
struct link *next;
};
struct link *poly1=NULL,*poly2=NULL,*poly=NULL;
void create(struct link *node)
{
char ch;
do
{
// clrscr();
printf(“\n Enter coeff : “);
scanf(“%d”,&node->coeff);
printf(” Enter power : “);
scanf(“%d”,&node->pow);
node->next=(struct link*)malloc(sizeof(struct link));
node=node->next;
node->next=NULL;
printf(“\n Continue(y/n):”);
ch=getch();
}
while(ch==’y’ || ch==’Y’);
}
void show(struct link *node)
{
while(node->next!=NULL)
{
printf(“%dx^%d”,node->coeff,node->pow);
node=node->next;
if(node->next!=NULL)
printf(” + “);
}
}
void polyadd(struct link *poly1,struct link *poly2,struct link *poly)
{
while(poly1->next && poly2->next)
{
if(poly1->pow>poly2->pow)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
else if(poly1->powpow)
{
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->next=(struct link *)malloc(sizeof(struct link));
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->next=(struct link *)malloc(sizeof(struct link));
poly=poly->next;
poly->next=NULL;
}
}
main()
{
char ch;
do{
clrscr();
poly1=(struct link *)malloc(sizeof(struct link));
poly2=(struct link *)malloc(sizeof(struct link));
poly=(struct link *)malloc(sizeof(struct link));
printf(“Enter 1st polinomial : “);
create(poly1);
clrscr();
printf(“Enter 2nd polinomial : “);
create(poly2);
clrscr();
printf(“1st polinomial : “);
show(poly1);
printf(“\n2nd polinomial : “);
show(poly2);
polyadd(poly1,poly2,poly);
printf(“\n\n Add of Two polynomial : “);
show(poly);
ch=getch();
}
while(ch==’y’ || ch==’Y’);
}

OUTPUT
Enter 1st polinomial :
Enter coeff : 10
Enter Power : 7
Continue(y/n): y
Enter coeff : 5
Enter Power : 4
Continue(y/n): y
Enter coeff : 3
Enter Power : 2
Continue(y/n): y
Enter coeff : 2
Enter Power : 0
Continue(y/n): n

Enter 2nd polinomial :
Enter coeff : 8
Enter Power : 6
Continue(y/n): y
Enter coeff : 4
Enter Power : 4
Continue(y/n): y
Enter coeff : 3
Enter Power : 3
Continue(y/n): y
Enter coeff : 6
Enter Power : 0
Continue(y/n): n

1st polinomial : 10x^7 + 5x^4 + 3x^3 + 2
2nd polinomial : 8x^6 + 4x^4 + 3x^2 + 6
Add of two polimanial: 10x^7 + 8x^6 + 9x^4 + 3x^3 + 3x^2 + 8
Leave a Reply

 

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here