Add to Favorites    Make Home Page 1826 Online  
 Language Categories  
 Our Services  

Home » C Home » Data Structures Home » PROGRAM TO ADD TWO POLYNOMIALS

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title PROGRAM TO ADD TWO POLYNOMIALS
Author Vishal Bhardwaj
Author Email vishal_with_me [at] rediffmail.com
Description
Category C » Data Structures
Hits 371701
Code Select and Copy the Code
/****************************************************************************** PROGRAM TO ADD TWO POLYNOMIALS ******************************************************************************/ #include<stdio.h> #include<conio.h> struct barbie { int coff; int pow; struct barbie *link; }*ptr,*start1,*node,*start2,*start3,*ptr1,*ptr2; typedef struct barbie bar; int temp1,temp2; void main() { void create(void); void prnt(void); void suml(void); void sort(void); clrscr(); printf(" Enrter the elements of the first poly :"); node = (bar *) malloc(sizeof (bar)); start1=node; if (start1==NULL) { printf(" Unable to create memory."); getch(); exit(); } create(); printf(" Enrter the elements of the second poly :"); node = (bar *) malloc(sizeof (bar)); start2=node; if (start2==NULL) { printf(" Unable to create memory."); getch(); exit(); } create(); clrscr(); //printing the elements of the lists printf(" The elements of the poly first are :"); ptr=start1; prnt(); printf(" The elements of the poly second are :"); ptr=start2; prnt(); printf(" The first sorted list is :"); ptr=start1; sort(); ptr=start1; prnt(); printf(" The second sorted list is :"); ptr=start2; sort(); ptr=start2; prnt(); printf(" The sum of the two lists are :"); suml(); ptr=start3; prnt(); getch(); } /*-----------------------------------------------------------------------------*/ void create() { char ch; while(1) { printf(" Enter the coff and pow :"); scanf("%d%d",&node->coff,&node->pow); if (node->pow==0 ) { ptr=node; node=(bar *)malloc(sizeof(bar)); node=NULL; ptr->link=node; break; } printf(" Do u want enter more coff ?(y/n)"); fflush(stdin); scanf("%c",&ch); if (ch=='n' ) { ptr=node; node=(bar *)malloc(sizeof(bar)); node=NULL; ptr->link=node; break; } ptr=node; node=(bar *)malloc(sizeof(bar)); ptr->link=node; } } /*-------------------------------------------------------------------------*/ void prnt() { int i=1; while(ptr!=NULL ) { if(i!=1) printf("+ "); printf(" %dx^%d ",ptr->coff,ptr->pow); ptr=ptr->link; i++; } //printf(" %d^%d",ptr->coff,ptr->pow); } /*---------------------------------------------------------------------------*/ void sort() { for(;ptr->coff!=NULL;ptr=ptr->link) for(ptr2=ptr->link;ptr2->coff!=NULL;ptr2=ptr2->link) { if(ptr->pow>ptr2->pow) { temp1=ptr->coff; temp2=ptr->pow; ptr->coff=ptr2->coff; ptr->pow=ptr2->pow; ptr2->coff=temp1; ptr2->pow=temp2; } } } /*---------------------------------------------------------------------------*/ void suml() { node=(bar *)malloc (sizeof(bar)); start3=node; ptr1=start1; ptr2=start2; while(ptr1!=NULL && ptr2!=NULL) { ptr=node; if (ptr1->pow > ptr2->pow ) { node->coff=ptr2->coff; node->pow=ptr2->pow; ptr2=ptr2->link; //update ptr list B } else if ( ptr1->pow < ptr2->pow ) { node->coff=ptr1->coff; node->pow=ptr1->pow; ptr1=ptr1->link; //update ptr list A } else { node->coff=ptr2->coff+ptr1->coff; node->pow=ptr2->pow; ptr1=ptr1->link; //update ptr list A ptr2=ptr2->link; //update ptr list B } node=(bar *)malloc (sizeof(bar)); ptr->link=node; //update ptr list C }//end of while if (ptr1==NULL) //end of list A { while(ptr2!=NULL) { node->coff=ptr2->coff; node->pow=ptr2->pow; ptr2=ptr2->link; //update ptr list B ptr=node; node=(bar *)malloc (sizeof(bar)); ptr->link=node; //update ptr list C } } else if (ptr2==NULL) //end of list B { while(ptr1!=NULL) { node->coff=ptr1->coff; node->pow=ptr1->pow; ptr1=ptr1->link; //update ptr list B ptr=node; node=(bar *)malloc (sizeof(bar)); ptr->link=node; //update ptr list C } } node=NULL; ptr->link=node; }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=712


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review