9. Data Structure Program | Read Now

Data Structure VTU lab program -9

• Design, Develop and Implement a Program in C for the following operations on Singly Circular Linked List (SCLL) with header nodes
1. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
2. 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

Program -9 code [scll.c]

```#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<math.h>
typedef struct node
{
int expo,coef;
struct node *next;
}node;
/*FUNCTION PROTOTYPE*/
node * insert(node *,int,int);
node * create();
int eval(node *p1);
{
node *p,*q;
p=(node *)malloc(sizeof(node));
p->expo=expo1;
p->coef=coef1;
p->next=NULL;
{
}

{
}
{
}
q=q->next;
if(p->expo==q->expo)
q->coef=q->coef+coef1;
else
{
p->next=q->next;
q->next=p;
}
}
node *create()
{
int n,i,expo1,coef1;
printf("\n\nEnter no of terms of polynomial==>");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n\nEnter coef & expo==>");
scanf("%d%d",&coef1,&expo1);
}
}
{
node *p;
p=p1->next;
do
{
p=p->next;
}while(p!=p1->next);
p=p2->next;
do
{
p=p->next;
}while(p!=p2->next);
}
{
node *p;
int x,ans=0;
printf("\n\nEnter the value of x=");
scanf("%d",&x);
do
{
ans=ans+p->coef*pow(x,p->expo);
p=p->next;
return(ans);
}
{
node *p,*q;
int n=0;
do
{
n++;
q=q->next;
printf("\n\n\tThe polynomial is==>");

do
{
if(n-1)
{
printf("%dx^(%d) + ",p->coef,p->expo);
p=p->next;
}
else
{
printf(" %dx^(%d)",p->coef,p->expo);
p=p->next;
}
n--;
}
void main()
{
int a,x,ch;
node *p1,*p2,*p3;
p1=p2=p3=NULL;
while(1)
{
printf("\n\tPolynomial Operations :");
printf("\n\t\t\t\t2.Evaluate");
printf("\n\t\t\t\t3.Exit");
printf("\n\t------------------------------------------- ");
scanf("%d",&ch);
switch(ch)
{
case 1 :
p1=create();
display(p1);
p2=create();
display(p2);
display(p3);
break;
case 2 :
p1=create();
display(p1);
a=eval(p1);
printf("\n\nValue of polynomial=%d",a);
break;
case 3 :
exit(0);
break;
default :
printf("\n\n\t invalid choice");
break;
}
}
} ```

Data Structure – How to Run this Program

• Step-1: Copy the above code
• Step-2: Paste it in any C compiler [Codeblocks/Dev C++/ VsCode etc]
• Step-3: Save the file name with .C extension
• Step-4: Compile the program
• Step-5: Run the program
• Step-6: Program Execution Successful