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

Pipeling, Asktypes of pipelining question #Minimum 100 words accepted#

Asktypes of pipelining question #Minimum 100 words accepted#

Merge sort , What is the best-case number of comparisons performed by merge...

What is the best-case number of comparisons performed by mergesort on an input sequence of 2 k distinct numbers?

A full binary tree with 2n+1 nodes, A full binary tree with 2n+1 nodes have...

A full binary tree with 2n+1 nodes have n non-leaf nodes

Define queue, A queue is a, FIFO (First In First Out) list.

A queue is a, FIFO (First In First Out) list.

Link list, algorithm for multiplication of two sparse matrices using link l...

algorithm for multiplication of two sparse matrices using link list

Determine the disjoint of division method, Determine the Disjoint of divisi...

Determine the Disjoint of division method A polygon is disjoint from the viewport if the x- and y-extents of the polygon do not overlap the viewport anywhere. In this case; reg

Splaying algorithm, Insertion & deletion of target key requires splaying of...

Insertion & deletion of target key requires splaying of the tree. In case of insertion, the tree is splayed to find the target. If, target key is found out, then we have a duplicat

Process of decision making under uncertainty, (a) Describe the steps involv...

(a) Describe the steps involved in the process of decision making under uncertainty. (b) Explain the following principles of decision making: (i) Laplace, (ii) Hurwicz. (c

Explain best - fit method, Best - Fit Method: - This method obtains the sma...

Best - Fit Method: - This method obtains the smallest free block whose  size is greater than or equal to get such a block by traversing the whole free list follows.

String pattern matching, Document processing is quickly becoming one of the...

Document processing is quickly becoming one of the dominant functions of computers. Computers are utilized to edit, search & transport documents over the Internet, and to display d

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