SlideShare a Scribd company logo
1 of 10
ADDITION OF
TWO POLYNOMIALS
Prepared by
Varsha Degaonkar
Department of Electronics and Telecommunication
Hope Foundation’s
International Institute of Information Technology, I²IT
www.isquareit.edu.in | info@isquareit.edu.in
https://www.geeksforgeeks.org/top-algorithms-and-data-structures-for-competitive-
programming/
ADDITION OF TWO POLYNOMIALS
2
#include<stdio.h>
#include<conio.h>
typedef struct poly
{ int power;
int coeff;
}poly;
void print(poly [], int);/*function declaration*/
We have created
user defined
datatype.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
3
void main()
{ int t1,t2,i,j,k;
poly p1[10],p2[10],p3[10];
clrscr();
printf("n Enter number of terms in 1st polynomial :");
scanf("%d",&t1);
for (i=0;i<t1;i++)
{ printf("n Enter a term(coeff. power)");
scanf("%d%d",&p1[i].coeff,&p1[i].power); }
printf("n1'st polynomial = ");
print(p1,t1); /*Function Call*/
Structure
variables
void print(poly p[],int n) /*Function Definition*/
{ int i;
for(i=0;i<n-1;i++)
printf("%dX^%d + ",p[i].coeff,p[i].power);
printf("%dX^%d =0 n",p[i].coeff,p[i].power);
}
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
4
printf("n Enter number of terms in 2nd polynomial :");
scanf("%d",&t2);
for (i=0;i<t2;i++)
{ printf("n Enter a term(coeff. power)");
scanf("%d%d",&p2[i].coeff,&p2[i].power);
}
printf("n2'nd polynomial = ");
print(p2,t2); /*Function Call*/
void print(poly p[],int n) /*Function Definition*/
{
int i;
for(i=0;i<n-1;i++)
printf("%dX^%d + ",p[i].coeff,p[i].power);
printf("%dX^%d =0 n",p[i].coeff,p[i].power);
}
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
5
i=j=k=0;
while(i<t1 || j<t2)
{ if(p1[i].power==p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff+p2[j].coeff;
i++;j++;k++;
}
else if(p1[i].power > p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff;
i++;k++;
}
else { p3[k].power=p2[j].power;
p3[k].coeff=p2[j].coeff;
j++;k++;
}
}
2X^6 + 5X^0 =0
i=0
7X^5 + 4X^0 =0
j=0
---------------------------------
2X^6 +
k=0
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
6
i=j=k=0;
while(i<t1 || j<t2)
{ if(p1[i].power==p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff+p2[j].coeff;
i++;j++;k++;
}
else if(p1[i].power > p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff;
i++;k++;
}
else { p3[k].power=p2[j].power;
p3[k].coeff=p2[j].coeff;
j++;k++;
}
}
2X^6 + 5X^0 =0
i=1
7X^5 + 4X^0 =0
j=0
---------------------------------
2X^6 +
k=0
7X^5 +
k=1
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
7
i=j=k=0;
while(i<t1 || j<t2)
{ if(p1[i].power==p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff+p2[j].coeff;
i++;j++;k++;
}
else if(p1[i].power > p2[j].power)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff;
i++;k++;
}
else { p3[k].power=p2[j].power;
p3[k].coeff=p2[j].coeff;
j++;k++;
}
}
2X^6 + 5X^0 =0
i=1
7X^5 + 4X^0 =0
j=1
---------------------------------
2X^6 +7X^5 +
k=0 k=1
9X^0 =0
k=2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
8
/* for rest over terms of polynomial 1 */
while(i<t1)
{ p3[k].power=p1[i].power;
p3[k].coeff=p1[i].coeff;
i++;k++;
}
/* for rest over terms of polynomial 2 */
while(j<t2)
{ p3[k].power=p2[j].power;
p3[k].coeff=p2[j].coeff;
j++;k++;
}
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
9
printf("n Addition of two polynomials = ");
print(p3,k); /*Function Call*/
getch();
}
void print(poly p[],int n) /*Function Definition*/
{
int i;
for(i=0;i<n-1;i++)
printf("%dX^%d + ",p[i].coeff,p[i].power);
printf("%dX^%d =0 n",p[i].coeff,p[i].power);
}
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
10
Thank you!!
For further details please contact
Prof. Varsha Degaonkar
varshad@isquareit.edu.in
Department of Electronics & Telecommunication
Hope Foundation’s
International Institute of Information Technology
I²IT
Hinjawadi, Pune
www.isquareit.edu.in
Ph. - +91 20 22933441
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

More Related Content

What's hot

What's hot (20)

Interrupt Handling with LPC2148
Interrupt Handling with LPC2148Interrupt Handling with LPC2148
Interrupt Handling with LPC2148
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
 
Human Computer Interaction - INPUT OUTPUT CHANNELS
Human Computer Interaction - INPUT OUTPUT CHANNELSHuman Computer Interaction - INPUT OUTPUT CHANNELS
Human Computer Interaction - INPUT OUTPUT CHANNELS
 
Basic Mechanical Engineering | Manufacturing Processes
Basic Mechanical Engineering | Manufacturing ProcessesBasic Mechanical Engineering | Manufacturing Processes
Basic Mechanical Engineering | Manufacturing Processes
 
Basics of Computer Graphics
Basics of Computer GraphicsBasics of Computer Graphics
Basics of Computer Graphics
 
What are the real differences between a wireframe, storyboard and a prototype?
What are the real differences between a wireframe, storyboard and a prototype?What are the real differences between a wireframe, storyboard and a prototype?
What are the real differences between a wireframe, storyboard and a prototype?
 
Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Systems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACCSystems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACC
 
Introduction to Wireless Sensor Networks (WSN)
Introduction to Wireless Sensor Networks (WSN)Introduction to Wireless Sensor Networks (WSN)
Introduction to Wireless Sensor Networks (WSN)
 
Conformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & ExamplesConformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & Examples
 
What Is LEX and YACC?
What Is LEX and YACC?What Is LEX and YACC?
What Is LEX and YACC?
 
Operating System Scheduling Algorithms
Operating System Scheduling AlgorithmsOperating System Scheduling Algorithms
Operating System Scheduling Algorithms
 
Introduction To Assembly Language Programming
Introduction To Assembly Language ProgrammingIntroduction To Assembly Language Programming
Introduction To Assembly Language Programming
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Cloud Computing & Virtual Infrastructure
Cloud Computing & Virtual InfrastructureCloud Computing & Virtual Infrastructure
Cloud Computing & Virtual Infrastructure
 
Data Structure - Linked List
Data Structure - Linked ListData Structure - Linked List
Data Structure - Linked List
 
Equivalence Calculation Under Inflation
Equivalence Calculation Under InflationEquivalence Calculation Under Inflation
Equivalence Calculation Under Inflation
 
Importance of Theory of Computations
Importance of Theory of ComputationsImportance of Theory of Computations
Importance of Theory of Computations
 
Introduction to Big Data, HADOOP: HDFS, MapReduce
Introduction to Big Data,  HADOOP: HDFS, MapReduceIntroduction to Big Data,  HADOOP: HDFS, MapReduce
Introduction to Big Data, HADOOP: HDFS, MapReduce
 

Similar to Addition of Two Polynomials

Deepika Mittal , BCA Third Year
Deepika Mittal , BCA Third YearDeepika Mittal , BCA Third Year
Deepika Mittal , BCA Third Yeardezyneecole
 
Gaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third YearGaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third Yeardezyneecole
 

Similar to Addition of Two Polynomials (20)

Singly Linked List & Data Structure
Singly Linked List & Data StructureSingly Linked List & Data Structure
Singly Linked List & Data Structure
 
Engineering Mathematics & Probability Distributions
Engineering Mathematics & Probability DistributionsEngineering Mathematics & Probability Distributions
Engineering Mathematics & Probability Distributions
 
Basics of Digital Electronics
Basics of Digital ElectronicsBasics of Digital Electronics
Basics of Digital Electronics
 
Introduction to TCP Protocol Suite
Introduction to TCP Protocol SuiteIntroduction to TCP Protocol Suite
Introduction to TCP Protocol Suite
 
Design Procedure for an Integrator
Design Procedure for an IntegratorDesign Procedure for an Integrator
Design Procedure for an Integrator
 
What Is Cascading Style Sheet?
What Is Cascading Style Sheet?What Is Cascading Style Sheet?
What Is Cascading Style Sheet?
 
Programming with LEX & YACC
Programming with LEX & YACCProgramming with LEX & YACC
Programming with LEX & YACC
 
NP-Complete Problem
NP-Complete Problem NP-Complete Problem
NP-Complete Problem
 
Differential Equation - Order Degree
Differential Equation - Order DegreeDifferential Equation - Order Degree
Differential Equation - Order Degree
 
DAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & ApplicationDAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & Application
 
Fundamentals of Computer Networks
Fundamentals of Computer NetworksFundamentals of Computer Networks
Fundamentals of Computer Networks
 
Python Data Structures Lists
Python Data Structures ListsPython Data Structures Lists
Python Data Structures Lists
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Pass Structure of Assembler
 
Red Black Tree Insertion & Deletion
Red Black Tree Insertion & DeletionRed Black Tree Insertion & Deletion
Red Black Tree Insertion & Deletion
 
Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)
 
What Is High Performance-Computing?
What Is High Performance-Computing?What Is High Performance-Computing?
What Is High Performance-Computing?
 
Document Type Definition (DTD)
Document Type Definition (DTD)Document Type Definition (DTD)
Document Type Definition (DTD)
 
Deepika Mittal , BCA Third Year
Deepika Mittal , BCA Third YearDeepika Mittal , BCA Third Year
Deepika Mittal , BCA Third Year
 
Gaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third YearGaurav Jatav , BCA Third Year
Gaurav Jatav , BCA Third Year
 
Interfacing of LCD with LPC2148
Interfacing of LCD with LPC2148Interfacing of LCD with LPC2148
Interfacing of LCD with LPC2148
 

More from International Institute of Information Technology (I²IT)

More from International Institute of Information Technology (I²IT) (20)

Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Understanding Natural Language Processing
Understanding Natural Language ProcessingUnderstanding Natural Language Processing
Understanding Natural Language Processing
 
What Is Smart Computing?
What Is Smart Computing?What Is Smart Computing?
What Is Smart Computing?
 
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
 
Writing Skills: Importance of Writing Skills
Writing Skills: Importance of Writing SkillsWriting Skills: Importance of Writing Skills
Writing Skills: Importance of Writing Skills
 
Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself
 
Servlet: A Server-side Technology
Servlet: A Server-side TechnologyServlet: A Server-side Technology
Servlet: A Server-side Technology
 
What Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It WorksWhat Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It Works
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Hypothesis-Testing
Hypothesis-TestingHypothesis-Testing
Hypothesis-Testing
 
Data Science, Big Data, Data Analytics
Data Science, Big Data, Data AnalyticsData Science, Big Data, Data Analytics
Data Science, Big Data, Data Analytics
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
 
What Is Cloud Computing?
What Is Cloud Computing?What Is Cloud Computing?
What Is Cloud Computing?
 
Introduction To Design Pattern
Introduction To Design PatternIntroduction To Design Pattern
Introduction To Design Pattern
 
Java as Object Oriented Programming Language
Java as Object Oriented Programming LanguageJava as Object Oriented Programming Language
Java as Object Oriented Programming Language
 
Data Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BIData Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BI
 
AVL Tree Explained
AVL Tree ExplainedAVL Tree Explained
AVL Tree Explained
 
Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
LR(0) PARSER
 
Land Pollution - Causes, Effects & Solution
Land Pollution - Causes, Effects & SolutionLand Pollution - Causes, Effects & Solution
Land Pollution - Causes, Effects & Solution
 

Recently uploaded

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 

Recently uploaded (20)

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 

Addition of Two Polynomials

  • 1. ADDITION OF TWO POLYNOMIALS Prepared by Varsha Degaonkar Department of Electronics and Telecommunication Hope Foundation’s International Institute of Information Technology, I²IT www.isquareit.edu.in | info@isquareit.edu.in https://www.geeksforgeeks.org/top-algorithms-and-data-structures-for-competitive- programming/
  • 2. ADDITION OF TWO POLYNOMIALS 2 #include<stdio.h> #include<conio.h> typedef struct poly { int power; int coeff; }poly; void print(poly [], int);/*function declaration*/ We have created user defined datatype. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 3. 3 void main() { int t1,t2,i,j,k; poly p1[10],p2[10],p3[10]; clrscr(); printf("n Enter number of terms in 1st polynomial :"); scanf("%d",&t1); for (i=0;i<t1;i++) { printf("n Enter a term(coeff. power)"); scanf("%d%d",&p1[i].coeff,&p1[i].power); } printf("n1'st polynomial = "); print(p1,t1); /*Function Call*/ Structure variables void print(poly p[],int n) /*Function Definition*/ { int i; for(i=0;i<n-1;i++) printf("%dX^%d + ",p[i].coeff,p[i].power); printf("%dX^%d =0 n",p[i].coeff,p[i].power); } Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 4. 4 printf("n Enter number of terms in 2nd polynomial :"); scanf("%d",&t2); for (i=0;i<t2;i++) { printf("n Enter a term(coeff. power)"); scanf("%d%d",&p2[i].coeff,&p2[i].power); } printf("n2'nd polynomial = "); print(p2,t2); /*Function Call*/ void print(poly p[],int n) /*Function Definition*/ { int i; for(i=0;i<n-1;i++) printf("%dX^%d + ",p[i].coeff,p[i].power); printf("%dX^%d =0 n",p[i].coeff,p[i].power); } Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 5. 5 i=j=k=0; while(i<t1 || j<t2) { if(p1[i].power==p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff+p2[j].coeff; i++;j++;k++; } else if(p1[i].power > p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff; i++;k++; } else { p3[k].power=p2[j].power; p3[k].coeff=p2[j].coeff; j++;k++; } } 2X^6 + 5X^0 =0 i=0 7X^5 + 4X^0 =0 j=0 --------------------------------- 2X^6 + k=0 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 6. 6 i=j=k=0; while(i<t1 || j<t2) { if(p1[i].power==p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff+p2[j].coeff; i++;j++;k++; } else if(p1[i].power > p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff; i++;k++; } else { p3[k].power=p2[j].power; p3[k].coeff=p2[j].coeff; j++;k++; } } 2X^6 + 5X^0 =0 i=1 7X^5 + 4X^0 =0 j=0 --------------------------------- 2X^6 + k=0 7X^5 + k=1 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 7. 7 i=j=k=0; while(i<t1 || j<t2) { if(p1[i].power==p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff+p2[j].coeff; i++;j++;k++; } else if(p1[i].power > p2[j].power) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff; i++;k++; } else { p3[k].power=p2[j].power; p3[k].coeff=p2[j].coeff; j++;k++; } } 2X^6 + 5X^0 =0 i=1 7X^5 + 4X^0 =0 j=1 --------------------------------- 2X^6 +7X^5 + k=0 k=1 9X^0 =0 k=2 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 8. 8 /* for rest over terms of polynomial 1 */ while(i<t1) { p3[k].power=p1[i].power; p3[k].coeff=p1[i].coeff; i++;k++; } /* for rest over terms of polynomial 2 */ while(j<t2) { p3[k].power=p2[j].power; p3[k].coeff=p2[j].coeff; j++;k++; } Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 9. 9 printf("n Addition of two polynomials = "); print(p3,k); /*Function Call*/ getch(); } void print(poly p[],int n) /*Function Definition*/ { int i; for(i=0;i<n-1;i++) printf("%dX^%d + ",p[i].coeff,p[i].power); printf("%dX^%d =0 n",p[i].coeff,p[i].power); } Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
  • 10. 10 Thank you!! For further details please contact Prof. Varsha Degaonkar varshad@isquareit.edu.in Department of Electronics & Telecommunication Hope Foundation’s International Institute of Information Technology I²IT Hinjawadi, Pune www.isquareit.edu.in Ph. - +91 20 22933441 International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in