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[6][2],poly2[6][2],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][0],&poly1[i][1]);

}

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

for(i=0;i

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

}

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][1]==poly2[j][1])

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

match=1;

}

}

}

for(i=0;i

{

 proceed=1;

for(j=0;j

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

else

proceed=0;

}

if (proceed==1)

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

}

for(i=0;i

{  proceed=1;

for(j=0;j

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

else

proceed=0;

}

if (proceed==1)

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

}

}

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.


Related Discussions:- Polynomials - represented by using arrays

Creation of Heap, Q. Create a heap with the given list of keys: ...

Q. Create a heap with the given list of keys: 8, 20, 9, 4, 15, 10, 7, 22, 3, 12                                                  Ans: Creation

Stack and queue, write a algorithsm in c to perform push and pop operation...

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Deletion algorithm for dequeue, Deletion Algorithm for dequeue Step 1:...

Deletion Algorithm for dequeue Step 1: [check for underflow]   If front = 0 and rear = 0   Output "underflow" and return Step 2: [delete element at front end]   If front

Algorithm to delete the specific node from binary searchtree, Q. Write down...

Q. Write down an algorithm to delete the specific node from binary search tree. Trace the algorithm to delete a node (10) from the following given tree. Ans. Algor

Stack, Explain in detail the algorithmic implementation of multiple stacks....

Explain in detail the algorithmic implementation of multiple stacks.

What is a container taxonomy, What is A Container Taxonomy It's useful ...

What is A Container Taxonomy It's useful to place containers in a taxonomy to help understand their relationships to one another and as a basis for implementation using a class

Define ordinary variable, Ordinary variable An ordinary variable of a e...

Ordinary variable An ordinary variable of a easy data type can store a one element only

What is binary search, What is binary search?   Binary search is most ...

What is binary search?   Binary search is most useful when list is sorted. In binary search, element present in middle of the list is determined. If key (the number to search)

ALGORITHM AND TRACING, WRITE AN ALGORITHM TO CONVERT PARENTHIZED INFIX TO P...

WRITE AN ALGORITHM TO CONVERT PARENTHIZED INFIX TO POSTFIX FORM ALSO TRACE ALG ON ((A+B)*C-(D-E)$F+G)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd