answersLogoWhite

0


Best Answer

#include

#include

struct polynode

{

float coeff;

int exp;

struct polynode *link;

};

void poly_append(struct polynode **,float,int);

void display_poly(struct polynode *);

void poly_multiply(struct polynode *, struct polynode *, struct polynode **);

void padd(float, int, struct polynode **);

main()

{

struct polynode *first, *second, *mult;

int i,coeff,exp,high;

first = second = mult = NULL;

printf("Enter the highest power of polynomial 1: \n");

scanf("%d",&high);

for(i=high;i>0;i--)

{

printf("Enter value for coeff for X^%d : ",i);

scanf("%d",&coeff);

poly_append(&first, coeff,i);

}

printf("\nEnter the highest power of polynomial 2: \n");

scanf("%d",&high);

for(i=high;i>0;i--)

{

printf("Enter value for coeff for X^%d : ",i);

scanf("%d",&coeff);

poly_append(&second, coeff,i);

}

printf("\n\n");

display_poly(&first);

printf("\n");

display_poly(second);

printf("\n");

for(i=1;i<=79;i++)

printf("-");

poly_multiply(first, second, &mult);

printf("\n");

display_poly(mult);

}

/* adds a term to a polynomial */

poly_append(struct polynode **q, float x, int y)

{

struct polynode *temp;

temp = *q;

/* create a new node if the list is empty */

if(*q NULL ) )

{

r = malloc ( sizeof ( struct polynode ) );

r -> coeff = c;

r -> exp = e;

r -> link = temp -> link;

temp -> link = r;

return;

}

temp = temp -> link; /* go to next node */

}

r -> link = NULL;

temp -> link = r;

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include <stdio.h>

#include <conio.h>

#include <math.h>

typedef struct node

{

int power;

float coeff;

struct node *next;

}node;

node * insert(node *head,int power1,float coeff1);

node * create();

node * padd(node *p1,node *p2);

node * pmul(node *p1,node *p2);

float eval(node *p1,float x);

void print(node *head);

node *insert(node *head,int power1,float coeff1)

{

node *p,*q;

p=(node*) malloc(sizeof(node));

p->power=power1;

p->coeff=coeff1;

p->next=NULL;

if(head==NULL)

{

head=p;

head->next=head;

return(head);

}

if(power1<head->power)

{

p->next=head->next;

head->next=p;

head=p;

return(head);

}

if(power1==head->power) //add coefficients

{

head->coeff=head->coeff+coeff1;

return(head);

}

q=head;

while(q->next!=head && power1<=q->next->power) //locate the postion for insertion

q=q->next;

if(p->power==q->power)

q->coeff=q->coeff+coeff1;

else

{

p->next=q->next;

q->next=p;

}

return(head);

}

node *create()

{

int n,i,power1;

float coeff1;

node *head=NULL;

printf("\nEnter No. of Terms:");

scanf("%d",&n);

printf("\nenter a term as a tuple of (power,coefficient) : ");

for(i=1;i<=n;i++)

{

scanf("%d%f",&power1,&coeff1);

head=insert(head,power1,coeff1);

}

return(head);

}

node * padd(node *p1,node *p2)

{

node *p;

node *head=NULL;

int power;float coeff;

p=p1->next;

do //insert the first polynomial

{

head=insert(head,p->power,p->coeff);

p=p->next;

} while(p!=p1->next);

p=p2->next;

do //insert the second polynomial

{

head=insert(head,p->power,p->coeff);

p=p->next;

} while(p!=p2->next);

return(head);

}

node *pmul(node *p1,node *p2)

{

node *head1,*head2;

node *head=NULL;

head2=p2->next;

do //for every term of the second polynomial

{

head1=p1->next;

do //multiply with every term of the first polynomial

{

head=insert(head,head1->power+head2->power,head1->coeff * head2->coeff);

head1=head1->next;

}while(head1!=p1->next);

head2=head2->next;

}while(head2!=p2->next);

return(head);

}

float eval(node *head,float x)

{

float value=0.00;

node *p;

p=head->next;

do

{

value=value+p->coeff * pow(x,p->power);

p=p->next;

}while(p!=head->next);

return(value);

}

void print( node *head)

{

node *p;

p=head->next;

printf("\n");

do

{

printf("%6.2fx^%d ",p->coeff,p->power);

p=p->next;

}while(p!=head->next);

}

void main()

{

node *p1,*p2,*p3;

int op;

float value,x;

p1=p2=p3=NULL;

clrscr();

do

{

printf("\n1)Create first polynomial");

printf("\n2)Create second polynomial");

printf("\n3)Print first polynomial");

printf("\n4)Print second polynomial");

printf("\n5)Add\n6)Multiply\n7)Evaluate First Polynomial\n8)Quit");

printf("\nEnter Your Choice: ");

scanf("%d",&op);

switch(op)

{

case 1: p1=create();break;

case 2: p2=create();break;

case 3: print(p1);break;

case 4: print(p2);break;

case 5: p3=padd(p1,p2);

print(p3);break;

case 6: p3=pmul(p1,p2);

print(p3);break;

case 7: printf("\nEnter the value of X:");

scanf("%f",&x);

value=eval(p1,x);

printf("\nEvaluated value = %6.2f",value);

break;

}

}while(op!=8);

}

/*

OUTPUT:

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 1

Enter No. of Terms:3

enter a term as a tuple of (power,coefficient) : 3 2 2 3 0 9

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 2

Enter No. of Terms:3

enter a term as a tuple of (power,coefficient) : 2 4 1 2 0 6

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 3

2.00x^3 3.00x^2 9.00x^0

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 4

4.00x^2 2.00x^1 6.00x^0

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 5

2.00x^3 7.00x^2 2.00x^1 15.00x^0

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 6

8.00x^5 16.00x^4 18.00x^3 54.00x^2 18.00x^1 54.00x^0

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 7

Enter the value of X:

2

Evaluated value = 37.00

1)Create first polynomial

2)Create second polynomial

3)Print first polynomial

4)Print second polynomial

5)Add

6)Multiply

7)Evaluate First Polynomial

8)Quit

Enter Your Choice: 8

*/

Written by: Fabianski Benjamin

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

write a program for multiplication of two polynomials. use doubly linked lists

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Polynomial multiplication in link list using c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Programfor addition of two polynomial using circular link list?

dsd


Write a c program add two polynomial using link list?

GOUDHMARINI


Give an example of a polynomial?

6x+5b+3, see related link for a thorough explanation of what a polynomial is.


What is the multiplication table?

This link gives you an excellent multiplication table and some tips.Please see related link below.


A brief introduction of polynomial?

The link to the left will give you the basics.


How many country people using Tamil language?

Tamil is mainly spoken in South India and parts of Sri Lanka, Singapore, and Malaysia. It is estimated that around 70-80 million people worldwide speak Tamil as their first language.


Using ANSI in C language?

The latest ANSI standard is C99. See the attached link.


What math website is there to get a multiplication chart?

See the Related Links section below for a link to a site with a good multiplication chart.


What is a link language?

Link language is just simple a language. With the help of link language we can make our contacts to others.Hindi for Indians, Japan i for Japanese Chinese for citizens of China are the link language . Except these there are some vernacular languages also serves as link language in particular countries. but which language should be accepted as International link language is still a matter of controversy.


How do you read the word on the rock where you get the regis?

The language on the rock is Braille. To read it I suggest using the related link below.


Where can I find multiplication facts worksheets?

Yes, i can point you in the right direction. please follow this link so you can find some multiplication facts worksheets sheets: math.about.com/cs/multiplication/a/multws.htm


Where are the math worksheets, related to multiplication?

The following link shall bring you to a website which specializes in math worksheets related to multiplication. They are used in schools and at home and can be printed off free of charge. Here is the link: http://www.tlsbooks.com/mathworksheets.htm