## 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.

#### Efficiency of linear search, Efficiency of Linear Search How much numbe...

Efficiency of Linear Search How much number of comparisons is there in this search in searching for a particular element? The number of comparisons based upon where the reco

#### The game tree, An interesting application or implementation of trees is the...

An interesting application or implementation of trees is the playing of games such as tie-tac-toe, chess, nim, kalam, chess, go etc. We can depict the sequence of possible moves

#### Design a binary search tree, Binary Search Tree usage: Write a progra...

Binary Search Tree usage: Write a program to compare the time taken for a search in a skewed tree, a balanced tree, and a random tree. Speci cally, your program should do the

#### Graph and BFS, traverse the graph as BFS

traverse the graph as BFS

#### Midsquare hash method, I want to example for midsquare method

I want to example for midsquare method

#### Dataset for dmi, The following DNA sequences are extracted from promoter re...

The following DNA sequences are extracted from promoter region of genes which are co-regulated by the same transcription factor (TF). The nucleotide segments capitalized in the giv

#### Deletion of a node from an avl tree, For AVL trees the deletion algorithm i...

For AVL trees the deletion algorithm is a little more complicated as there are various extra steps involved in the deletion of node. If the node is not a leaf node, then it contain

#### Implementation of stack using linked lists, In the last subsection, we have...

In the last subsection, we have implemented a stack by using an array. While a stack is implemented by using arrays, it suffers from the basic restriction of an array - i.e., its s

#### Insertion into a red-black tree, The insertion procedure in a red-black tre...

The insertion procedure in a red-black tree is similar to a binary search tree i.e., the insertion proceeds in a similar manner but after insertion of nodes x into the tree T, we c

#### State the symbols of abstract data type operation, Symbols of ADT oepration...

Symbols of ADT oeprations All Symbol ADT operations are implemented in Symbol class, except toSymbol(), which is implemented in classes (like String) which can generate a Symb  