/* * ass16.c polynomial operations */ #include #include typedef struct term { float coeff ; int exp; struct term *next; } term, *poly; poly initPoly(); int isZero(poly); term *makeMono(float, int); void insertTerm(poly, term *); void readPoly(poly); void printPoly(poly); poly addPoly(poly, poly); poly multPoly(poly, poly); int main() { poly p, q, r; p = initPoly(); q = initPoly(); printf("Enter exponent of x and the coefficient "); printf("Terminate with -ve exp:\n"); readPoly(p); printf("Polynomial p: "); printPoly(p); printf("Enter exponent of x and the coefficient "); printf("Terminate with -ve exp:\n"); readPoly(q); printf("Polynomial q: "); printPoly(q); r = addPoly(p,q); printf("Polynomial p + q: "); printPoly(r); r = multPoly(p,q); printf("Polynomial p X q: "); printPoly(r); return 0; } poly initPoly(){ poly p; p = (poly)malloc(sizeof(term)); p->next = (poly)malloc(sizeof(term)); p->next->exp = 0; p->next->coeff = 0.0; p->next->next = NULL; return p; } int isZero(poly p){ return (p->next->exp == 0) && (p->next->coeff == 0.0); }