CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  1 links from elsewhere to this Post. Click to view. #1 (permalink)
Old 27th February 2008, 08:54 PM
CE - Newbie
 
I'm a Crazy Electronics & Telecommunication Engineer
Join Date: 18th November 2007
Posts: 7
Default C function for addition of two single variable polynomials

can any1 tel me wat may be c code for writing function to add 2 single variable polynomials of length say n&m?
upgrade is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 27th February 2008, 09:12 PM
CE - Newbie
 
I'm a Crazy Electronics & Telecommunication Engineer
Join Date: 18th November 2007
Posts: 7
Default c code

can anyone giv me c code for addition of two single variable polynomials.
upgrade is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 28th February 2008, 02:55 AM
CE - Addict
 
mahul's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 14th November 2007
Location: kolkata
Posts: 275
Send a message via Yahoo to mahul
Default Re: C function for addition of two single variable polynomials

please be a little more elaborate if u can, like how u represent and store ur polynomials, the arguments u would like to pass to ur function and such stuff. By what u have posted, there was very little that i could comprehend.
__________________

An apple changed the world, it fell on Newton's head

My Blog
mahul is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 28th February 2008, 07:20 PM
CE - Newbie
 
I'm a Crazy Electronics & Telecommunication Engineer
Join Date: 18th November 2007
Posts: 7
Default Re: C function for addition of two single variable polynomials

i want to accept any length two polynomials like say 6x^3+5x^2
and 4x^2+5x+7
now i hav to take powers and coefficients of x from user.i hav done that.
but now i need to add these polynomials.
upgrade is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 2nd March 2008, 06:00 AM
CE - Addict
 
friendster7's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 4th February 2008
Location: india,karnataka
Posts: 386
Send a message via Yahoo to friendster7
Default Re: C function for addition of two single variable polynomials

Quote:
mynode *polynomial_add(mynode *h1, mynode *h2, mynode *h3)
{
mynode *p1, *p2;
int x1, x2, y1, y2, cf1, cf2, cf;

p1 = h1->next;

while(p1!=h1)
{
x1 = p1->px;
y1 = p1->py;
cf1 = p1->cf;

// Search for this term in the second polynomial

p2 = h2->next;

while(p2 != h2)
{
x2 = p2->px;
y2 = p2->py;
cf2 = p2->cf;

if(x1 == x2 && y1 == y2)break;

p2 = p2->next;

}


if(p2 != h2)
{
// We found something in the second polynomial.

cf = cf1 + cf2;
p2->flag = 1;

if(cf!=0){h3=addNode(cf,x1,y1,h3);}
}
else
{
h3=addNode(cf,x1,y1,h3);
}

p1 = p1->next;

}//while


// Add the remaining elements of the second polynomail to the result

while(p2 != h2)
{
if(p2 -> flag ==0)
{
h3=addNode(p2->cf, p2->px, p2->py, h3);
}
p2=p2->next;
}

return(h3);
}
this will help u i guess..this can add two polynomials
friendster7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)
Old 17th November 2008, 10:10 PM
CE - Apprentice
 
I'm a Crazy Computer Science & Engineering Engineer
Join Date: 16th November 2008
Location: India
Posts: 10
Default Re: C function for addition of two single variable polynomials

I just joined the site and would like to contribute in here
Code in PASCAL using linked list
{Program to perform polynomial addition using linked list}
Code:
PROGRAM polyaddll(input,output);
TYPE nodeptr=^node;
     node=RECORD
     coef:integer;
     exp:integer;
     link:nodeptr;
     END;
VAR one,two,res:nodeptr;
    k:integer;
PROCEDURE print(n:nodeptr);
VAR p:nodeptr;
BEGIN
     p:=n;
     WHILE (p<>NIL) DO
     BEGIN
          write(p^.coef,' X^ ',p^.exp);
          IF (p^.link<>NIL) THEN
             write(' + ');
          p:=p^.link;
     END;
     writeln;
END;
PROCEDURE create(VAR n:nodeptr);
VAR p,q:nodeptr;
    c:char;
BEGIN
     c:='y';
     WHILE (c<>'n') DO
     BEGIN
          new(p);
          write('Enter the coefficient of the term : ');
          readln(k);
          p^.coef:=k;
          write('Enter the exponent of the term : ');
          readln(k);
          p^.exp:=k;
          p^.link:=NIL;
          write('Do you want to add any more terms (Y/N) : ');
          readln(c);
          IF (n=NIL) THEN
          BEGIN
               n:=p;
               q:=p;
          END
          ELSE
          BEGIN
               q^.link:=p;
               q:=p;
          END;
     END;
END;
PROCEDURE sum(VAR a,b,c:nodeptr);
VAR p,q,r,s:nodeptr;
BEGIN
     p:=a;
     q:=b;
     WHILE ((p<>NIL) AND (q<>NIL)) DO
     BEGIN
          new(r);
          r^.link:=NIL;
          IF (p^.exp>q^.exp) THEN
          BEGIN
               r^.coef:=p^.coef;
               r^.exp:=p^.exp;
               p:=p^.link;
          END
          ELSE
              IF (q^.exp>p^.exp) THEN
              BEGIN
                   r^.coef:=q^.coef;
                   r^.exp:=q^.exp;
                   q:=q^.link;
              END
              ELSE
              BEGIN
                   r^.coef:=p^.coef+q^.coef;
                   r^.exp:=p^.exp;
                   p:=p^.link;
                   q:=q^.link;
              END;
          IF (c=NIL) THEN
          BEGIN
               c:=r;
               s:=r;
          END
          ELSE
          BEGIN
               s^.link:=r;
               s:=r;
          END;
     END;
     WHILE (p<>NIL) DO
     BEGIN
          new(r);
          r^.coef:=p^.coef;
          r^.exp:=p^.exp;
          r^.link:=NIL;
          p:=p^.link;
          IF (c=NIL) THEN
          BEGIN
               c:=r;
               s:=r;
          END
          ELSE
          BEGIN
               s^.link:=r;
               s:=r;
          END;
     END;
     WHILE (q<>NIL) DO
     BEGIN
          new(r);
          r^.coef:=q^.coef;
          r^.exp:=q^.exp;
          r^.link:=NIL;
          q:=q^.link;
          IF (c=NIL) THEN
          BEGIN
               c:=r;
               s:=r;
          END
          ELSE
          BEGIN
               s^.link:=r;
               s:=r;
          END;
     END;
END;
BEGIN
     one:=NIL;
     two:=NIL;
     res:=NIL;
     writeln('Enter the first polynomial : ');
     create(one);
     writeln('Enter the second polynomial : ');
     create(two);
     writeln('The first polynomial is  : ');
     print(one);
     writeln('The second polynomial is : ');
     print(two);
     sum(one,two,res);
     writeln('The reult of addition is : ');
     print(res);
     readln;
END.
We Rock!!!!!!!

Last edited by The_Big_K : 17th November 2008 at 10:15 PM.
Ashutosh_shukla is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.crazyengineers.com/forum/computer-science-engineering/2122-c-function-addition-two-single-variable-polynomials.html
Posted By For Type Date
Uniting Engineers Across The World ! This thread Refback 28th February 2008 10:38 AM


All times are GMT +5.5. The time now is 10:41 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger