Add Polynomials

Add ploynomials using linked list

Page 1 of 1

4 Replies - 9038 Views - Last Post: 07 April 2008 - 08:45 AM Rate Topic: -----

#1 man5237  Icon User is offline

  • New D.I.C Head

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

Add Polynomials

Posted 04 April 2008 - 08:28 AM

Write a program in C programming language to add two polynomials
using linked list.?
Is This A Good Question/Topic? 0
  • +

Replies To: Add Polynomials

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

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.

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


You can search and find lots of examples of implementing linked lists in C
Was This Post Helpful? 0
  • +
  • -

#3 man5237  Icon User is offline

  • New D.I.C Head

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

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.
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

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.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

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: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1