POLYNOMIALS (Using Linked List) |
Polynomial: E.g.: 3x5 - 2x3 + x2 + 4 The important information about the polynomial is contained in the coefficients and exponents of x; the variable x itself is just a place holder (a dummy variable). We can think of a polynomial as a sum of terms, each of which consists of a coefficient and an exponent. It can be represented as a list of pairs of coefficients and exponents. A linked list is preferable to a contiguous list for representing a polynomial because we may not know the bound on the degree, or only a few non-zero terms may appear. Functionality Implemented in this Program:
|
C Language Code: |
POLYNOM.H |
// DSTC -- POLYNOM.H -- polynomial header file .. //#include "assert.h" typedef struct polynominal typedef struct polynominallist poly *createpoly(void) void addterm(poly *p,float c,int e) poly *addpoly(poly *p1, poly *p2) while(t1 && t2) while (t1) while (t2) return(p3); // prints the polynomial void printpoly(poly *p) temp = temp->next ; } void killpoly(poly *p) |
POLYNOM.CPP |
#include <stdio.h> main() clrscr() ; printf("\n Enter the 1st Term of Poly in Coeff,Exponent form:" ); addterm(p,c,e) ; printf("\n Enter the 2nd Term of Poly in Coeff,Exponent form:" ); addterm(p,c,e) ;
printf("\n Enter the 3rd Term of Poly in Coeff,Exponent form:") ; addterm(p,c,e) ; printf("\n Print Polynomial ...\n") ; printpoly(p); printf("\n Enter the 1st Term of Poly in Coeff,Exponent form:" ); addterm(p1,c,e) ; printf("\n Enter the 2nd Term of Poly in Coeff,Exponent form:" ); res=addpoly(p,p1) ; } |
We are trying to contribute to the net what ever Technical knowledge. I Believe that knowledge increases by spreading and sharing with others.
Tuesday, January 30, 2024
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment