ADDITION OF TWO POLYNOMIALS

Slides:



Advertisements
Similar presentations
Recursion Prog #include <stdio.h> #include<conio.h> main()
Advertisements

Sort the given string, without using string handling functions.
Enumerated Data Type. An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name of the (optional) enumeration.
Polynomial Addition using Linked lists
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
FUNCTIONS A function is a set of instructions that can perform a specific task accordingly. A function is a program that performs a specific task according.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Chapter 11 Structures, Unions and Typedef 11.1 Structures Structures allow us to group related data items of different types under a common name. The individual.
Why Should You Get Your Air Conditioning System Serviced Before Summer?
Chapter 4 Function and Structure.
LESSON 3 IO, Variables and Operators
MULTI-DIMENSIONAL ARRAY
CHAPTER 12 LINKED LIST SRM-MCA.
Winter Gardening Tips
Guide to Understand Back Pain
Don't Forget to Tune up Your Furnace for Winter
Visit for more Learning Resources
CHAPTER 7 RECURSIVE FUNCTION
Website: Contact No: ID:
Tejalal Choudhary “C Programming from Scratch” Pointers
Visit for more Learning Resources
Buy book Online -
Buy book Online -
S. Kiran, PGT (CS) KV, Malleswaram
DESIGN PATTERNS : Strategy Pattern
COMPUTER NETWORK TECHNOLOGY
DESIGN PATTERNS : State Pattern
DESIGN PATTERNS : Introduction
Red Black Tree Prof. Keshav Tambre Assistant Professor Department of Information Technology Hope Foundation’s International Institute of Information Technology,
Physics of Nanoparticles
Composition & Resolution of Forces
DESIGN PATTERNS : Adapter Pattern
Usability Heuristics Prof
EQUIVALENCE CALCULATIONS UNDER INFLATION
NP-COMPLETE Prof. Manjusha Amritkar Assistant Professor Department of Information Technology Hope Foundation’s International Institute of Information.
International Institute of Information Technology, (I²IT).
Engineering Mathematics-I Eigenvalues and Eigenvectors
Software Design Methodologies and Testing
Pass Structure of Assembler
INTERNATIONAL INSTITUTE OF IFORMATION TECHNOLOGY, (I²IT)
INTERNATIONAL INSTITUTE OF IFORMATION TECHNOLOGY, (I²IT)
Cloud Computing Prof. Sachindra Chavan Assistant Professor
Newton’s Laws of Motion
By Sandeep Patil, Department of Computer Engineering, I²IT
Differential Equation
BINARY HEAP Prof ajitkumar shitole Assistant Professor Department of computer engineering Hope Foundation’s International Institute of Information.
Pass Structure of Assembler
Types of Corrosion Dr. Swati Kolet Assistant Professor
gyroscope Prof Varsha Degaonkar Assistant Professor
Introduction to TCP/IP protocol Suite
Hope Foundation’s International Institute of Information.
Essay Writing Writing is an art Prepared by Vaidehi Banerjee
Introduction to Human Computer Interaction
Design procedure for an Integrator
Engineering Mathematics-III Probability Dristibution
Artificial Intelligence
Basic Electrical Engg. UNIT:-IV AC Fundamental
Prof. Deptii Chaudhari.
Tel Hope Foundation’s International Institute of Information Technology, (I²IT). Tel
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
INTERNATIONAL INSTITUTE OF IFORMATION TECHNOLOGY, (I²IT)
DAA - Introduction Dr. Sashikala Mishra Associate Professor Department of Computer Engineering Hope Foundation’s INTERNATIONAL INSTITUTE OF INFORMATION.
Tel Hope Foundation’s International Institute of Information Technology, (I²IT). Tel
Introduction to Microwave
Transaction Serializability
CASCADING STYLE SHEET WEB TECHNOLOGY
Visit for more Learning Resources
Presentation transcript:

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 #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

void print(poly p[],int n) /*Function Definition*/ { int i; 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

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

--------------------------------- 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

--------------------------------- 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

--------------------------------- 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

/. for rest over terms of polynomial 1. / while(i<t1) { p3[k] /* 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

printf("\n Addition of two polynomials = "); print(p3,k); / 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

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