Page 1 of 1

## 4 Replies - 9373 Views - Last Post: 07 April 2008 - 08:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=48123&amp;s=b1afb95afe94a3b58873503a36a5758f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 man5237

Reputation: 1
• Posts: 11
• Joined: 04-April 08

Posted 04 April 2008 - 08:28 AM

Write a program in ‘C’ programming language to add two polynomials
Is This A Good Question/Topic? 0

### #2 NickDMax

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07

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.

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

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

### #3 man5237

Reputation: 1
• Posts: 11
• Joined: 04-April 08

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.

### #4 NickDMax

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07

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.

### #5 NickDMax

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07