Explanation Program

56
PROGRAM : #include<stdio.h> #include<conio.h> struct record { char first_name[15]; char sur_name[15]; int age; float salary; }r; void main( ) { FILE *f; char c='y'; clrscr( ); f=fopen("Sequential Text.txt ","w"); while(c=='y') { printf("FILE MANIPULATION - SEQUENTIAL ACCESS TEXT FILE"); printf("\nenter the first_name, sur_name , age and salary of the employee "); scanf("\n %s%s%d %f",r.first_name,r.sur_name,&r.age,&r.salary); fprintf(f,"%s \t %s \t %d \t %f \ n",r.first_name,r.sur_name,r.age,r.salary); printf("\n do you want to enter more y/n? \n"); c=getch( ); } fclose(f); printf("\n Records are\n"); f=fopen("Sequential Text ","r"); while(!feof(f))

Transcript of Explanation Program

PROGRAM :

#include<stdio.h>#include<conio.h>struct record{char first_name[15];char sur_name[15];int age;float salary;}r;void main( ){FILE *f;char c='y';clrscr( );f=fopen("Sequential Text.txt ","w");while(c=='y'){printf("FILE MANIPULATION - SEQUENTIAL ACCESS TEXT FILE");printf("\nenter the first_name, sur_name , age and salary of the employee ");scanf("\n %s%s%d%f",r.first_name,r.sur_name,&r.age,&r.salary);fprintf(f,"%s \t %s \t %d \t %f \n",r.first_name,r.sur_name,r.age,r.salary);printf("\n do you want to enter more y/n? \n");c=getch( );}fclose(f);printf("\n Records are\n");f=fopen("Sequential Text ","r");while(!feof(f)){fscanf(f,"%s \t %s \t %d \t %f \n",,r.first_name,r.sur_name,&r.age,&r.salary);

printf("\n first_name=%s \t sur_name =%s \t age=%d \t salary=%f \n ",r.first_name,r.sur_name,r.age,r.salary);

}fclose(f);getch( );}

OUTPUT :

FILE MANIPULATION - SEQUENTIAL ACCESS TEXT FILE

Enter the first name raj

Enter the sur name kumar

Enter age 55

Enter salary 566

do you want to enter more y/n? y

FILE MANIPULATION - SEQUENTIAL ACCESS TEXT FILE

Enter the first name rakesh

Enter the sur name kumar

Enter age 55

Enter salary 5443

do you want to enter more y/n? n

Records are

Sur name=raj name=kumar age=55 salary=566.000000

Sur name=rakesh name=kumar age=75 salary=5443.000000

PROGRAM :

#include<stdio.h>#include<conio.h>void main( ){FILE *fp;long int n;char c;clrscr( );printf("FILE MANIPULATION - RANDOM ACCESS TEXT FILE \n ");fp=fopen("Random text.txt","w+");while((c=getchar( ))!=EOF)fputc(c,fp);printf("Number of characters entered=%ld",ftell(fp));n=0L;while(feof(fp)==0){fseek(fp,n,0);printf("position of %c is %ld ",fgetc(fp),ftell(fp));n=n+5L;}putchar('\n');

fseek(fp,-1L,2);do{putchar(fgetc(fp));}while(!fseek(fp,-2L,1));fclose(fp);getch( );}

OUTPUT :

FILE MANIPULATION - RANDOM TEXT FILE

ABCDEFGHIJKLMNOPQRSTUVWXYZ ^Z ( ctrl + z) to entering EOF character

Number of characters entered=26

position of A is 0 position of F is 5 position of K is 10 position of P is 15 position of U is 20 position of Z is 25

position of   is 30

ZYXWVUTSRQPONMLKJIHGFEDCBA

PROGRAM :#include<stdio.h>#include<conio.h>struct record{char first_name[15];char last_name[15];int age;int salary;}r[3];void main( ){FILE *f;int b;int i=0;clrscr( );f=fopen("Sequential Binary.BIN","wb");while(i<=3){printf("FILE MANIPULATION - SEQUENTIAL ACCESS BINARY FILE \n ");printf("\nenter the first_name, last_name ,age and salary of the employee ");scanf("\n %s %s%d%d",r[i].first_name,r[i].last_name,r[i].age,r[i].salary);fwrite(&r[i],sizeof(r[i]),1,f);i++;}fclose(f);printf("Records are\n");f=fopen("Sequential Binary.BIN ","rb");while(!feof(f)){b=fread(&r[0],sizeof(r[0]),3,f);if(b!=NULL){for(i=0;i<3;i++)printf(" first_name=%s \t last_name=%s \t age=%d \t salary=%d \n" ,r[i].first_name,r[i].last_name,r[i].age,r[i].salary);} }fclose(f);getch( ); }

OUTPUT :

FILE MANIPULATION - SEQUENTIAL ACCESS BINARY FILE

Enter the first name raj

Enter the last name kumar

Enter age 7

Enter salary 6555

FILE MANIPULATION - SEQUENTIAL ACCESS BINARY FILE

Enter the first name mukesh

Enter the last name kumar

Enter age 23

Enter salary 5544

FILE MANIPULATION - SEQUENTIAL ACCESS BINARY FILE

Enter the first name lokesh

Enter the last name kumar

Enter age 56

Enter salary 4445

Records are

First name=raj last name=kumar age=7 salary=6555

First name=mukesh last name=kumar age=23 salary=5544

First name=lokesh last name=kumar age=56 salary=4445

PROGRAM :

#include<stdio.h>#include<conio.h>struct record{char first_name[15];char last_name[15];int age;float salary;}r;void main( ){FILE *f;int count=0,rec,b;char c='y';clrscr();f=fopen("Random Binary.BIN","wb");while(c=='y'){printf(" FILE MANIPULATION – RANDOM ACCESS BINARY FILE \n ");count++;printf("\nenter the first name, last name , age and salary of the employee ");scanf("\n %s%s%d%f",r.first_name,r.last_name,&r.age,&r.salary);fwrite(&r,sizeof(r),1,f);printf("\n do you want to enter more y/n? \n");c=getch( );}fclose(f);printf("\nfrom which record do you want to read [1-%d]\n",count);scanf("\n%d",&rec);f=fopen("Random Binary.BIN","rb");

if(rec<=count && rec>0){fseek(f,(rec-1)*sizeof(r),0);while(!feof(f)){b=fread(&r,sizeof(r),1,f);if(b!=NULL)

printf("\n first_name=%s \t last_name=%s \t age=%d \t salary=%f \n",r.first_name,r.last_name,r.age,r.salary);

}}elseprintf("wrong choice");fclose(f);getch( );}

OUTPUT :

FILE MANIPULATION - RANDOM ACCESS BINARY FILEenter the first name rajeeventer the last name kumarenter age 20enter salary 23000.00

do you want to enter more y/n? y

FILE MANIPULATION - RANDOM ACCESS BINARY FILEenter the first name vinayenter the last name kumarenter age 23enter salary 34000.00

do you want to enter more y/n? y

FILE MANIPULATION - RANDOM ACCESS BINARY FILEenter the first name mukeshenter the last name kumarenter age 78enter salary 45000.00

do you want to enter more y/n? n

Records are

First name=rajeev last name=kumar age=20 salary=23000.00First name=vinay last name=kumar age=23 salary=34000.00First name=mukesh last name=kumar age=78 salary=45000.00

from which record do you want to read [1-3]2First name=mukesh last name=kumar age=78 salary=45000.00

from which record do you want to read [1-3]4wrong choiceSINGLY LINKED LIST PROGRAM :

#include<stdio.h>#include<conio.h>struct node{int id;char name[10];long int salary;struct node *next;};typedef struct node emp;emp *first=NULL;emp *last=NULL;void create( );void insert(int);void del(int);void search(int);void display(int);int merge(int);void main( ){int count=0,i,ch;clrscr( );while(1){printf("enter the choice\n1.create list\n2.insert record\n3.del record\n4.search record\n5.display records\n6.merge\n7.exit\n");scanf("%d",&ch);switch(ch){case 1:create( );count++;break;case 2:insert(count);

count++;break;case 3:delete(count);count--;break;case 4:search(count);break;case 5:display(count);break;case 6:count=merge(count);break;default:exit(0);}}}void create( ){emp *e=(emp*)malloc(sizeof(emp)); printf("enter id,name and salary of the employee\n");scanf("%d%s%ld",&e->id,e->name,&e->salary);e->next=NULL; first=e;first->next=NULL;last=e; last->next=NULL; printf("list has created with one record\n");}

void insert(int c) c is the number of nodes in a list{

int pos,i;emp *temp,*temp1,*e;printf("enter position to insert(0-%d)",c); get the position to insertscanf("%d",&pos);e=(emp*)malloc(sizeof(emp));printf("enter id,name and salary of the employee\n");scanf("%d%s%ld",&e->id,e->name,&e->salary);

if(pos==c) Insert Node Insertion At Last Position{e->next=NULL; make the next node address as NULL for the new nodelast->next=e; make the new node as next node of last nodelast=e; make the new node as last node as e.printf("one record is inserted at position %d\n",pos);}

else if(pos==0) Insert Node Insertion At Initial Position {e->next=first; make the first node as next node of new nodefirst=e; make the new node as new first node as eprintf("one record is inserted at position %d\n",pos);}

else Insert Node Insertion At Middle Position {temp=first; Assign the first node address to the tempfor(i=1;i<=pos;i++) Traverse the list from position 1 to required position {temp1=temp; Consider the previous node address to temp1 in each iterationtemp=temp->next; Consider the current node address to temp in each iteration}temp1->next=e; new node as next node of previous node of given positione->next=temp; current node of given position as next node of new node printf("one record has been inserted at position %d\n",pos);}}

void display(int n)

{int i;emp *temp;temp=first;printf("list of records\n");printf("id\tname\tsalary\n");for(i=0;i<n;i++){printf("%d\t%d\t%s\t%ld\t%p\n",i,temp->id,temp->name,temp->salary,temp);temp=temp->next;}}

void del(int r){int i,dpos;emp *temp,*temp1;printf("enter position to delete (0-%d)\n",r-1);scanf("%d",&dpos);

if(dpos==0) Delete Node Insertion At Initial Position {first=first->next; make the next node of first node as new first node}

else if the position is other than first{temp=first; //assign the address of first node to tempfor(i=1;i<=dpos;i++) //traverse the list from 1 to required position{temp1=temp; //assign the previous node address to temp1 in each iterationtemp=temp->next; //assign the current node address to temp in each iteration}

if(temp==last) //if the position is last{last=temp1; //make the previous node of last node as new last nodelast->next=first; //make the next node of new last node as first nodefree(temp); // free the memory space allocated for previous last node for others use}else //if the position is intermediate {temp1->next=temp->next; //make the next node of given position as next node previous node of given positionfree(temp); // free the memory space allocated for the node which

is in given position for others use }}printf("one record has been deleted from the postion %d\n",dpos);}

void search(int s){int n,i,flag=0;emp *temp;temp=first;printf("enter id value to search the record\n");scanf("%d",&n);for(i=0;i<s;i++){if(temp->id==n){flag=1;printf("the position of the record is%d\n",i);printf("the record is\nid\t%d\nname\t%s\nsalary\t%ld\n",temp->id,temp->name,temp->salary);break;}

elsetemp=temp->next;}if(flag==0)printf("the record is not present in the list\n");}

int merge(int m){int i,n;emp *temp,*first1,*e;printf("enter no.of records in the second list");scanf("%d",&n);printf("create the second list with %d records",n);e=(emp *)malloc(sizeof(emp));scanf("%d%s%ld",&e->id,e->name,&e->salary);e->next=NULL;temp=first1=e;for(i=1;i<n;i++){emp *e=(emp*)malloc(sizeof(emp));scanf("%d%s%ld",&e->id,e->name,&e->salary);e->next=NULL;temp->next=e;temp=temp->next;}last->next=first1;last=temp;return(m+n);}

OUTPUT :

enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit1enter id,name and salary of the employee 111 raju 63456 0A38enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit2enter position to insert(0-1)?1enter id,name and salary of the employee 222 rajesh 8485one record is inserted at position 1enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit6enter no.of records in the second list 2create the second list with 2 records333 sunil 854444 ajith 848enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit5list of records

id name salary0 111 raju 634564 0A381 222 rajesh 8485 0A4E2 333 sunil 854 0A643 444 ajith 848 0A7A

CIRCULAR LINKED LIST PROGRAM :

#include<stdio.h>#include<conio.h>struct node{int id;char name[10];long int salary;struct node *next;};typedef struct node emp;emp *first=NULL;emp *last=NULL;void create( );void insert(int);void del(int);void search(int);void display(int);int merge(int);void main( ){int count=0,i,ch;clrscr( );while(1){printf("enter the choice\n1.create list\n2.insert record\n3.del record\n4.search record\n5.display records\n6.merge\n7.exit");

scanf("%d",&ch);switch(ch){case 1:create( );count++;break;case 2:insert(count);count++;break;case 3:del(count);count--;break;case 4:search(count);break;case 5:display(count);break;case 6:count=merge(count);break;default:exit(0);}}}

void create( ){emp *e=(emp*)malloc(sizeof(emp));printf("enter id,name and salary of the employee\n");scanf("%d%s%ld",&e->id,e->name,&e->salary);

e->next=NULL;first=e;first->next=NULL;last=e;last->next=first;printf("list has created with one record\n");}void insert(int c){int pos,i;emp *temp,*temp1,*e;printf("enter position to insert(0-%d)?",c);scanf("%d",&pos);e=(emp*)malloc(sizeof(emp));printf("enter id,name and salary of the employee\n");scanf("%d%s%ld",&e->id,e->name,&e->salary);

if(pos==c){e->next=NULL;last->next=e;last=e;last->next=first;printf("one record is inserted at position %d\n",pos);}

else if(pos==0){e->next=first;first=e;printf("one record is inserted at position %d\n",pos);}

else{temp=first;for(i=1;i<=pos;i++){temp1=temp;

temp=temp->next;}temp1->next=e;e->next=temp;printf("one record has been inserted at position %d\n",pos);}}

void display(int n){int i;emp *temp,*addr;temp=first;printf("list of records\n");printf("id \t name \t salary \n");

for(i=0;i<n;i++){printf("%d \t %d \t %s \t %ld \t %p \n",i,temp->id,temp->name,temp->salary,temp);

temp=temp->next;}printf("enter address to display address from particular node");scanf("%p",&addr);temp=addr;printf("%d \t %s \t %ld \t %p \n",temp->id,temp->name,temp->salary,temp);

while(temp->next!=addr){temp=temp->next;

printf("%d \t %s \t %ld \t %p \n",temp->id,temp->name,temp->salary,temp);}

}

void del(int r){int i,dpos;emp *temp,*temp1;printf("enter position to delete (0-%d)\n",r-1);scanf("%d",&dpos);

if(dpos==0){first=first->next;}

else{temp=first;for(i=1;i<=dpos;i++){temp1=temp;temp=temp->next;}

if(temp==last){temp1->next=NULL;last=temp1;last->next=first;}else

temp1->next=temp->next;}printf("one record has been deleted from the postion %d\n",dpos);}

void search(int s){int n,i,flag=0;emp *temp;temp=first;printf("enter id value to search the record\n");scanf("%d",&n);

for(i=0;i<s;i++){if(temp->id==n){flag=1;printf("the position of the record is%d\n",i);

printf("the record is \n id \t %d \n name \t %s \n salary \t %ld \n",temp->id,temp->name,temp->salary);

break;}elsetemp=temp->next;}if(flag==0)printf("the record is not present in the list\n");}

int merge(int m){int i,n;emp *temp,*first1,*e;printf("enter no.of records in the second list");scanf("%d",&n);printf("create the second list with %d records",n);e=(emp *)malloc(sizeof(emp));scanf("%d%s%ld",&e->id,e->name,&e->salary);e->next=NULL;temp=first1=e;for(i=1;i<n;i++){emp *e=(emp*)malloc(sizeof(emp));scanf("%d%s%ld",&e->id,e->name,&e->salary);e->next=NULL;temp->next=e;temp=temp->next;}last->next=first1;last=temp;return(m+n);}

OUTPUT :enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit1 enter id,name and salary of the employee id name salary0 4 ravi 5465 0A24list has created with one recordenter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit2enter position to insert(0-1)? 1enter id, name salary of the employee6 ram 86878

one record is inserted at position 1enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit 2 enter position to insert(0-2)? 2 enter id ,name salary of the employee9 ragav 78696one record is inserted at position 2enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit5

list of records id name salary0 4 ravi 5465 0A861 6 ram 86878 0A9C2 9 ragav 78696 0AB2

enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit

6enter no.of records in the second list 2create the second list with 2 records100 sunil 8575200 rakesh 7478

enter the choice1.create list 2.insert record 3.delete record 4.search record 5.display records6.merge 7.exit5list of records id name salary0 4 ravi 5465 0A861 6 ram 86878 0A9C2 9 ragav 78696 0AB23 100 sunil 8575 0AC84 200 rakesh 7478 0ADE

enter address to display address from particular node 0AB2 9 ragav 78696 0AB2 100 sunil 8575 0AC8 200 rakesh 7478 0ADE 4 ravi 5465 0A86 6 ram 86878 0A9C

DOUBLY LINKED LIST PROGRAM :

#include<stdio.h>

#include<conio.h>

struct employee

{

int id;

char name[10];

int salary;

struct employee *next;

struct employee *prev;

};

typedef struct employee emp;

emp *first=NULL;

emp *last=NULL;

void create( );

void insert(int);

void delete(int);

void search(int);

void display(int);

int merge(int);

void main( )

{

int count=0,i,ch;

clrscr( );

while(1)

{

printf("enter the choice\n1.create list\n2.insert record\n3.delete record\n4.search record\n5.display records\n6.merge\n7.exit\n");

scanf("%d",&ch);

switch(ch)

{

case 1:

create( );

count++;

break;

case 2:

insert(count);

count++;

break;

case 3:

delete(count);

count--;

break;

case 4:

search(count);

break;

case 5:

display(count);

break;

case 6:

count=merge(count);

break;

default:

exit(0);

}

}

}

void create( )

{

emp *e=(emp*)malloc(sizeof(emp));

printf("enter id,name and salary of the employee\n");

scanf("%d%s%d",&e->id,e->name,&e->salary);

e->next=NULL;

e->prev=NULL;

first=e;

last=e;

}

void insert(int n)

{

int pos,i;

emp *e;

printf("Enter the position to insert (0-%d)",n);

scanf("%d",&pos);

e=(emp*)malloc(sizeof(emp));

printf("enter id,name and salary of the employee\n");

scanf("%d%s%d",&e->id,e->name,&e->salary);

e->next=NULL;

e->prev=NULL;

if(pos==n)

{

last->next=e;

e->prev=last;

last=e;

}

else if(pos==0)

{

e->next=first;

first->prev=e;

first=e;

}

else

{

emp *temp,*temp1;

temp=first;

for(i=1;i<=pos;i++)

{

temp1=temp;

temp=temp->next;

}

temp1->next=e;

e->prev=temp1;

e->next=temp;

temp->prev=e;

}

}

void display(int n)

{

int i;

emp *temp,*temp1;

temp=first;

temp1=last;

printf("list of records from first\n");

printf("id\tname\tsalary\n");

for(i=0;i<n;i++)

{

printf("%d\t%d\t%s\t%d\t%p\n",i,temp->id,temp->name,temp->salary,temp);

temp=temp->next;

}

printf("list of records from last\n");

printf("id\tname\tsalary\n");

for(i=0;i<n;i++)

{printf("%d\t%d\t%s\t%d\t%p\n",i,temp1->id,temp1->name,temp1->salary,temp1);

temp1=temp1->prev;

}

}

void delete(int n)

{

int i,pos;

emp *temp,*temp1;

printf("enter position to delete (0-%d)\n",n-1);

scanf("%d",&pos);

if(pos==0)

{

temp=first;

first=first->next;

first->prev=NULL;

free(temp);

}

else if(pos==n-1)

{

for(i=1;i<=pos;i++)

{

temp=temp->next;

}

temp1=temp->next;

temp->next=NULL;

last=temp;

free(temp1);

}

else

{

temp1=first;

for(i=1;i<pos;i++)

{

temp=temp->next;

}

temp1=temp->next;

temp->next=temp1->next;

temp1->prev=temp;

free(temp1);

} }

void search(int s)

{

int n,i,flag=0;

emp *temp;

temp=first;

printf("enter id value to search the record\n");

scanf("%d",&n);

for(i=0;i<s;i++)

{

if(temp->id==n)

{

flag=1;

printf("the position of the record is%d\n",i);

printf("the record is\nid\t%d\nname\t%s\nsalary\t%ld\n",temp->id,temp->name,temp->salary);

break;

}

else

temp=temp->next;

}

if(flag==0)

printf("the record is not present in the list\n");

}

int merge(int m)

{

int i,n;

emp *temp,*first1,*e;

printf("enter no.of records in the second list");

scanf("%d",&n);

printf("create the second list with %d records",n);

e=(emp *)malloc(sizeof(emp));

scanf("%d%s%ld",&e->id,e->name,&e->salary);

e->next=NULL;

temp=first1=e;

for(i=1;i<n;i++)

{

emp *e=(emp*)malloc(sizeof(emp));

scanf("%d%s%ld",&e->id,e->name,&e->salary);

e->next=NULL;

temp->next=e;

temp=temp->next;

}

last->next=first1;

last=temp;

return(m+n);

}

OUTPUT :

enter the choice

1.create list2.insert record3.delete record4.search record5.display records6.exit

1

enter id,name and salary of the employee

3 raj 23000

enter the choice1.create list2.insert record3.delete record4.search record5.display records6.exit

2

Enter the position to insert (0-1) 1

enter id,name and salary of the employee

6 kumar 340000

enter the choice1.create list2.insert record

3.delete record4.search record5.display records6.exit

5

list of records from first

id name salary

0 3 raj 23000 0948

1 6 kumar 12320 095E

list of records from last

id name salary

0 6 kumar 12320 095E

1 3 raj 23000 0948

#include<stdio.h>

struct polynomial

{

int coeff;

int deg;

struct polynomial *next;

};

typedef struct polynomial poly;

poly *first1=NULL,*first2=NULL,*first3=NULL;

poly *last1=NULL,*last2=NULL,*last3=NULL;

void polysum(poly*,poly*);

void display();

void polymul(poly*,poly*);

void create(poly**,poly**);

void main()

{

while(1)

{

int c;

printf("\nenter choice\n1.create poly1\n2.create poly2\n3.add\n4.mul\n5.exit\n");

scanf("%d",&c);

switch(c)

{

case 1:create(&first1,&last1);

break;

case 2:create(&first2,&last2);

break;

case 3:

first3=NULL;

last3=NULL;

polysum(first1,first2);

printf("resultant polynomial\n");

display();

break;

case 4:

first3=NULL;

last3=NULL;

polymul(first1,first2);

printf("resultant polynomial\n");

display();

break;

default:exit(0);

}

}

//getch();

}

void create(poly **first,poly **last)

{

poly *pn;

int p,i;

printf("enter no.of terms for polynomial1\n");

scanf("%d",&p);

printf("enter coeff and degree from higher degree to lower degree\n");

pn=(poly*)malloc(sizeof(poly));

scanf("%d%d",&pn->coeff,&pn->deg);

pn->next=NULL;

*first=pn;

*last=pn;

for(i=1;i<p;i++)

{

pn=(poly*)malloc(sizeof(poly));

scanf("%d%d",&pn->coeff,&pn->deg);

pn->next=NULL;

(*last)->next=pn;

*last=pn;

}

}

void polysum(poly *pn1,poly *pn2)

{

poly *pn3;

while(pn1!=NULL && pn2!=NULL)

{

pn3=(poly*)malloc(sizeof(poly));

pn3->next=NULL;

if(first3==NULL)

{

first3=pn3;

last3=pn3;

}

else

{

last3->next=pn3;

last3=pn3;

}

if(pn1->deg==pn2->deg)

{

pn3->coeff=pn1->coeff+pn2->coeff;

pn3->deg=pn1->deg;

pn1=pn1->next;

pn2=pn2->next;

}

else if(pn1->deg>pn2->deg)

{

pn3->coeff=pn1->coeff;

pn3->deg=pn1->deg;

pn1=pn1->next;

}

else

{

pn3->coeff=pn2->coeff;

pn3->deg=pn2->deg;

pn2=pn2->next;

}

}

while(pn1!=NULL)

{

pn3=(poly*)malloc(sizeof(poly));

pn3->coeff=pn1->coeff;

pn3->deg=pn1->deg;

pn3->next=NULL;

last3->next=pn3;

last3=pn3;

pn1=pn1->next;

}

while(pn2!=NULL)

{

pn3=(poly*)malloc(sizeof(poly));

pn3->coeff=pn2->coeff;

pn3->deg=pn2->deg;

pn3->next=NULL;

last3->next=pn3;

last3=pn3;

pn2=pn2->next;

}

}

void display()

{

poly *temp;

for(temp=first3;temp!=NULL;temp=temp->next)

{

printf("%dx^%d\t",temp->coeff,temp->deg);

}

}

void polymul(poly *pn1,poly *pn2)

{

poly *pn3;

int mul,de;

while(pn2!=NULL)

{

pn1=first1;

while(pn1!=NULL)

{

mul=pn1->coeff*pn2->coeff;

de=pn1->deg+pn2->deg;

if(first3==NULL)

{

pn3=(poly*)malloc(sizeof(poly));

pn3->coeff=mul;

pn3->deg=de;

pn3->next=NULL;

first3=pn3;

last3=pn3;

}

else

{

poly *temp,*temp1;

int flag=0;

temp=first3;

while(temp!=NULL)

{

if(temp->deg==de)

{

temp->coeff=temp->coeff+mul;

flag=1;

break;

}

else

{

temp=temp->next;

}

}

if(flag==0)

{

pn3=(poly*)malloc(sizeof(poly));

pn3->coeff=mul;

pn3->deg=de;

pn3->next=NULL;

temp=first3;

while(temp!=NULL)

{

if(temp->deg>de)

{

if(temp==last3)

{

last3->next=pn3;

last3=pn3;

break;

}

else

{

temp1=temp;

temp=temp->next;

}

}

else

{

if(temp==first3)

{

pn3->next=first3;

first3=pn3;

break;

}

else

{

temp1->next=pn3;

pn3->next=temp;

break;

}

}

}

}

}

pn1=pn1->next;

}

pn2=pn2->next;

}

}