## Polynomials - represented by using arrays, Data Structure & Algorithms

Assignment Help:

/* the program accepts two polynomials as a input & prints the resultant polynomial because of the addition of input polynomials*/

#include

void main()

{

int poly1,poly2,term1,term2,match,proceed,i,j;

printf("Enter the number of terms in first polynomial. They must be less than 6:\n");

scanf("%d",&term1);

printf("Enter the number of terms in the second polynomial. They must be less than 6:\n");

scanf("%d",&term2);

printf("Enter the exponent and coefficient of every term of the first polynomial:\n");

for(i=0;i

{scanf("%d %d",&poly1[i],&poly1[i]);

}

printf("Enter the exponent and coefficient of every term of the second polynomial:\n");

for(i=0;i

{scanf("%d %d",&poly2[i],&poly2[i]);

}

printf("The resulting polynomial because of the addition of the input two polynomials:\n");

for(i=0;i

{

match=0;

for(j=0;j

{ if (match==0)

if(poly1[i]==poly2[j])

{ printf("%d   %d\n",(poly1[i]+poly2[j]), poly1[i]);

match=1;

}

}

}

for(i=0;i

{

proceed=1;

for(j=0;j

{  if(proceed==1) if(poly1[i]!=poly2[j]) proceed=1;

else

proceed=0;

}

if (proceed==1)

printf("%d %d\n",poly1[i],poly1[i]);

}

for(i=0;i

{  proceed=1;

for(j=0;j

{  if(proceed==1) if(poly2[i]!=poly1[j]) proceed=1;

else

proceed=0;

}

if (proceed==1)

printf("%d %d",poly2[i],poly2[i]);

}

}

Output:

Enter the number of terms in first polynomial. They must be less than 6: 5. Enter the number of terms in the second polynomial .They must be less than 6: 4. Enter the coefficient & exponent of each of term of the first polynomial:

1 2

2 4

3 6

1 8

5 7

Enter the coefficient & exponent of every term of the second polynomial:

5 2

6 9

3 6

5 7

The resultant polynomial because of the addition of the input two polynomials:

6 2

6 6

10 7

2 4

1 8

6 9

The program prompted initially for number of terms of the two polynomials. Then, this prompted for the entry of terms of the 2 polynomials one after another. At first, this adds the coefficients of the corresponding terms of both the polynomials whose exponents are the similar. Then, this prints the terms of the primary polynomial who does not contain corresponding terms in the second polynomial along with the same exponent. Lastly, it prints the terms of the second polynomial that does not contain corresponding terms in the first polynomial.

#### Explain the different types of traversal on binary tree, Question 1 What i...

Question 1 What is a data structure? Discuss briefly on types of data structures Question 2 Explain the insertion and deletion operation of linked list in detail Qu

#### Algorithms, write short note on algorithms

write short note on algorithms

#### Basic organization of computer system, what happen''s in my computer when ...

what happen''s in my computer when i input any passage

#### B-TREE and AVL tree diffrance, Explain process of B-TREE and what differen...

Explain process of B-TREE and what difference between AVL Tree Using Algorithms

#### Binary tree with depth 3, Q. Construct a complete binary tree with depth 3 ...

Q. Construct a complete binary tree with depth 3 for this tree which is maintained in the memory using the linked representation. Make the adjacency list and adjacency matrix for t

#### Data flow diagrams, How to construct a data flow diagram for a college assi...

How to construct a data flow diagram for a college assignment and marking systemA

#### Booth algorithm, what is boot algorithm and some example

what is boot algorithm and some example

#### State flowchart that take temperature input using pseudocode, Write an algo...

Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the num

#### Non-recursive algorithm, Q .  Write down the non-recursive algorithm to tra...

Q .  Write down the non-recursive algorithm to traverse a tree in preorder. Ans: T he Non- Recursive algorithm for preorder traversal is written below: Initially i

#### Functions for inserting and deleting at either end of deque, Q. Devise a re...

Q. Devise a representation for a given list where insertions and deletions can be made at both the ends. Such a structure is called Deque (which means Double ended queue). Write fu  