Lab Program 9
Lab Program 9
Develop a Program in C for the following operations on Singly Circular Linked List
(SCLL) with header nodes
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the
result in POLYSUM(x,y,z)
Support the program with appropriate functions for each of the above operations
#include <stdio.h>
#include <stdlib.h>
int coeff;
int exp_x;
int exp_y;
int exp_z;
} Node;
newNode->coeff = coeff;
newNode->exp_x = exp_x;
newNode->exp_y = exp_y;
newNode->exp_z = exp_z;
1
newNode->next = NULL;
return newNode;
void insertTerm(Node** poly, int coeff, int exp_x, int exp_y, int exp_z) {
if (*poly == NULL) {
*poly = newNode;
newNode->next = *poly;
} else {
temp = temp->next;
temp->next = newNode;
newNode->next = *poly;
if (poly == NULL) {
printf("Polynomial is empty\n");
return;
2
}
do {
if (temp->next != poly) {
printf("+ ");
temp = temp->next;
printf("\n");
do {
temp1 = temp1->next;
temp2 = temp2->next;
3
int main() {
// Represent and Evaluate Polynomial P(x,y,z) = 6x^2y^2z - 4yz^5 + 3x^3yz + 2xy^5z - 2xyz^3
insertTerm(&polyP, 6, 2, 2, 1);
insertTerm(&polyP, 3, 3, 1, 1);
insertTerm(&polyP, 2, 1, 5, 1);
displayPoly(polyP);
insertTerm(&poly1, 2, 2, 2, 1);
insertTerm(&poly1, 5, 0, 0, 5);
insertTerm(&poly1, 3, 1, 5, 1);
displayPoly(poly1);
// Represent and Evaluate Polynomial POLY2(x,y,z) = 4x^2y^2z - 3yz^5 + 2x^3yz - xy^5z + 2xyz^3
insertTerm(&poly2, 4, 2, 2, 1);
4
insertTerm(&poly2, -3, 0, 0, 5);
insertTerm(&poly2, 2, 3, 1, 1);
insertTerm(&poly2, 2, 1, 1, 3);
displayPoly(poly2);
displayPoly(polySum);
// Free memory
free(polyP);
free(poly1);
free(poly2);
free(polySum);
return 0;
5
OUTPUT