Write a program in ‘C’ programming language to add two polynomials

using linked list.?

## 4 Replies - 9529 Views - Last Post: 07 April 2008 - 08:45 AM

##
**Replies To:** Add Polynomials

### #2

## Re: Add Polynomials

Posted 04 April 2008 - 09:49 AM

Generally speaking you can represent a polynomial in memory by storing the coefficients. For example 3 + 2x + 3x^2 + 4x^3... can be represented by [3, 2, 3, 4...] i.e. just the coefficients.

So what you want to do is store a series of coefficients into a linked list.

So a0 + a1*x + a2*x^2 + a3*x^3... an*x^n will be stored as the series [a0, a1, a2, a3 ..., an] and b0 + b1*x + ... + am*x^m will be [b0, b1, ... bn]. To add the polynomials you add like terms: A(x) + B(x) = [a0+b0, a1+b1,...an+bn...].

Not really very hard. The hard part is making the linked list. A linked list is an abstract data structure used to store data in memory. You create a struct with a value and a pointer. The pointer either points to the next node or it is NULL. It is a very handy structure for dealing with dynamic memory allocation.

You can search and find lots of examples of implementing linked lists in C

So what you want to do is store a series of coefficients into a linked list.

So a0 + a1*x + a2*x^2 + a3*x^3... an*x^n will be stored as the series [a0, a1, a2, a3 ..., an] and b0 + b1*x + ... + am*x^m will be [b0, b1, ... bn]. To add the polynomials you add like terms: A(x) + B(x) = [a0+b0, a1+b1,...an+bn...].

Not really very hard. The hard part is making the linked list. A linked list is an abstract data structure used to store data in memory. You create a struct with a value and a pointer. The pointer either points to the next node or it is NULL. It is a very handy structure for dealing with dynamic memory allocation.

struct node { double value; node *next; };

You can search and find lots of examples of implementing linked lists in C

### #3

## Re: Add Polynomials

Posted 07 April 2008 - 08:37 AM

I am a novice in the field of C programming.

So please write all the steps of the program.

Please.

Thanks in advance.

So please write all the steps of the program.

Please.

Thanks in advance.

### #4

## Re: Add Polynomials

Posted 07 April 2008 - 08:45 AM

google!!!! Right off I got this.

Steps:

Put coefficients in lists.

traverse lists.

Add coefficients, storing result in new list.

when you reach the end of the shorter list, continue on to copy remaining coefficients in longer list.

This is not complicated.

start by learning how to implement a linked list. Once you have one of those this is EASY.

Steps:

Put coefficients in lists.

traverse lists.

Add coefficients, storing result in new list.

when you reach the end of the shorter list, continue on to copy remaining coefficients in longer list.

This is not complicated.

start by learning how to implement a linked list. Once you have one of those this is EASY.

### #5

## Re: Add Polynomials

Posted 07 April 2008 - 08:45 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this:

Thanks.

Post your code like this:

Thanks.

Page 1 of 1