SlideShare a Scribd company logo
A polynomial may be represented as a linked list where each node contains the coefficient and
exponent of a term of the polynomial. The polynomial 4 X^3 - 3 X^2 - 5 would be represented as
the linked list. Write a program system that reads two polynomials, stores them as linked lists,
adds them together, and prints the result as a polynomial. The result should be a third linked list.
Travers both polynomials. If a particular exponent value is present in cither of the two
polynomials being summed, then it should be present in the answer. If it is present in both
polynomials, then its coefficient is the sum of the corresponding coefficient in both polynomials.
(If this sum is zero, the term should be deleted).
Solution
#include
#include
typedef struct link
{
int coeff;
int pow;
struct link * next;
} my_poly;
void my_create_poly(my_poly **);
void my_show_poly(my_poly *);
void my_add_poly(my_poly **, my_poly *, my_poly *);
int main(void)
{
int ch;
do {
my_poly * poly1, * poly2, * poly3;
printf(" Create 1st expression ");
my_create_poly(&poly1);
printf(" Stored the 1st expression");
my_show_poly(poly1);
printf(" Create 2nd expression ");
my_create_poly(&poly2);
printf(" Stored the 2nd expression");
my_show_poly(poly2);
my_add_poly(&poly3, poly1, poly2);
my_show_poly(poly3);
printf(" Add two more expressions? (Y = 1/N = 0): ");
scanf("%d", &ch);
} while (ch);
return 0;
}
void my_create_poly(my_poly ** node)
{
int flag;
int coeff, pow;
my_poly * tmp_node;
tmp_node = (my_poly *) malloc(sizeof(my_poly));
*node = tmp_node;
do
{
printf(" Enter Coeff:");
scanf("%d", &coeff);
tmp_node->coeff = coeff;
printf(" Enter Pow:");
scanf("%d", &pow);
tmp_node->pow = pow;
tmp_node->next = NULL;
printf(" Continue adding more terms to the polynomial list?(Y = 1/N = 0): ");
scanf("%d", &flag);
//printf(" FLAG: %c ", flag);
if(flag)
{
tmp_node->next = (my_poly *) malloc(sizeof(my_poly)); //Grow the list
tmp_node = tmp_node->next;
tmp_node->next = NULL;
}
} while (flag);
}
void my_show_poly(my_poly * node)
{
printf(" The polynomial expression is: ");
while(node != NULL)
{
printf("%dx^%d", node->coeff, node->pow);
node = node->next;
if(node != NULL)
printf(" + ");
}
}
void my_add_poly(my_poly ** result, my_poly * poly1, my_poly * poly2)
{
my_poly * tmp_node;
tmp_node = (my_poly *) malloc(sizeof(my_poly));
tmp_node->next = NULL;
*result = tmp_node;
while(poly1 && poly2)
{
if (poly1->pow > poly2->pow)
{
tmp_node->pow = poly1->pow;
tmp_node->coeff = poly1->coeff;
poly1 = poly1->next;
}
else if (poly1->pow < poly2->pow)
{
tmp_node->pow = poly2->pow;
tmp_node->coeff = poly2->coeff;
poly2 = poly2->next;
}
else
{
tmp_node->pow = poly1->pow;
tmp_node->coeff = poly1->coeff + poly2->coeff;
poly1 = poly1->next;
poly2 = poly2->next;
}
if(poly1 && poly2)
{
tmp_node->next = (my_poly *) malloc(sizeof(my_poly));
tmp_node = tmp_node->next;
tmp_node->next = NULL;
}
}
while(poly1 || poly2)
{
tmp_node->next = (my_poly *) malloc(sizeof(my_poly));
tmp_node = tmp_node->next;
tmp_node->next = NULL;
if(poly1)
{
tmp_node->pow = poly1->pow;
tmp_node->coeff = poly1->coeff;
poly1 = poly1->next;
}
if(poly2)
{
tmp_node->pow = poly2->pow;
tmp_node->coeff = poly2->coeff;
poly2 = poly2->next;
}
}
printf(" Addition Complete");
}
output:
Create 1st expression
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):
Enter Coeff:
Enter Pow:
Continue adding more terms to the polynomial list?(Y = 1/N = 0):

More Related Content

Similar to A polynomial may be represented as a linked list where each node cont.pdf

Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdf
aonesalem
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
ambersushil
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdf
amarnathmahajansport
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
Nishant Munjal
 
iit c prog.ppt
iit c prog.pptiit c prog.ppt
iit c prog.ppt
KauserJahan6
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
anjanacottonmills
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
ajajkhan16
 
2. operator
2. operator2. operator
2. operator
Shankar Gangaju
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
php user defined functions
php user defined functionsphp user defined functions
php user defined functions
vishnupriyapm4
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
Pavan Babu .G
 
Pointer in C
Pointer in CPointer in C
Pointer in C
bipchulabmki
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2docSrikanth
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
ManjeeraBhargavi Varanasi
 

Similar to A polynomial may be represented as a linked list where each node cont.pdf (20)

Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdf
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
C code examples
C code examplesC code examples
C code examples
 
iit c prog.ppt
iit c prog.pptiit c prog.ppt
iit c prog.ppt
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
2. operator
2. operator2. operator
2. operator
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
php user defined functions
php user defined functionsphp user defined functions
php user defined functions
 
C important questions
C important questionsC important questions
C important questions
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 

More from fashionfolionr

Discuss the benefits of in-built coding software within the Health I.pdf
Discuss the benefits of in-built coding software within the Health I.pdfDiscuss the benefits of in-built coding software within the Health I.pdf
Discuss the benefits of in-built coding software within the Health I.pdf
fashionfolionr
 
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
Determine if each system is1. memoryless2. Invertible3. Causal.pdfDetermine if each system is1. memoryless2. Invertible3. Causal.pdf
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
fashionfolionr
 
According to the Fick equation, what happens to J when X (the distanc.pdf
According to the Fick equation, what happens to J when X (the distanc.pdfAccording to the Fick equation, what happens to J when X (the distanc.pdf
According to the Fick equation, what happens to J when X (the distanc.pdf
fashionfolionr
 
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
A 14 foot ladder is leaning against a building. If the bottom of the.pdfA 14 foot ladder is leaning against a building. If the bottom of the.pdf
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
fashionfolionr
 
Briefly discuss operating system, firmware, and utility programs..pdf
Briefly discuss operating system, firmware, and utility programs..pdfBriefly discuss operating system, firmware, and utility programs..pdf
Briefly discuss operating system, firmware, and utility programs..pdf
fashionfolionr
 
Assume that scores on the LSAT are approximately normally distribute.pdf
Assume that scores on the LSAT are approximately normally distribute.pdfAssume that scores on the LSAT are approximately normally distribute.pdf
Assume that scores on the LSAT are approximately normally distribute.pdf
fashionfolionr
 
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
All answers must be in your own wordsWhat iswas The Great Law Wh.pdfAll answers must be in your own wordsWhat iswas The Great Law Wh.pdf
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
fashionfolionr
 
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
fashionfolionr
 
Write a function prototype for each of the following functions (Jus.pdf
Write a function prototype for each of the following functions (Jus.pdfWrite a function prototype for each of the following functions (Jus.pdf
Write a function prototype for each of the following functions (Jus.pdf
fashionfolionr
 
Why is white collar crime is so difficult to address with law enforc.pdf
Why is white collar crime is so difficult to address with law enforc.pdfWhy is white collar crime is so difficult to address with law enforc.pdf
Why is white collar crime is so difficult to address with law enforc.pdf
fashionfolionr
 
What is Eulers number and who is it named after Can you name some.pdf
What is Eulers number and who is it named after Can you name some.pdfWhat is Eulers number and who is it named after Can you name some.pdf
What is Eulers number and who is it named after Can you name some.pdf
fashionfolionr
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdfUsing C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdf
fashionfolionr
 
Unless specifically legally permitted, agreements to suppress or eli.pdf
Unless specifically legally permitted, agreements to suppress or eli.pdfUnless specifically legally permitted, agreements to suppress or eli.pdf
Unless specifically legally permitted, agreements to suppress or eli.pdf
fashionfolionr
 
There are tremendous pressures on selected industrialized countries,.pdf
There are tremendous pressures on selected industrialized countries,.pdfThere are tremendous pressures on selected industrialized countries,.pdf
There are tremendous pressures on selected industrialized countries,.pdf
fashionfolionr
 
This week we covered Accounting and Payroll liabilities and the diff.pdf
This week we covered Accounting and Payroll liabilities and the diff.pdfThis week we covered Accounting and Payroll liabilities and the diff.pdf
This week we covered Accounting and Payroll liabilities and the diff.pdf
fashionfolionr
 
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdft Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
fashionfolionr
 
Stark Company has five employees. Employees paid by the hour receive.pdf
Stark Company has five employees. Employees paid by the hour receive.pdfStark Company has five employees. Employees paid by the hour receive.pdf
Stark Company has five employees. Employees paid by the hour receive.pdf
fashionfolionr
 
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdfSilas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
fashionfolionr
 
Q1 Discuss three types of accounting anomalies and define why they .pdf
Q1 Discuss three types of accounting anomalies and define why they .pdfQ1 Discuss three types of accounting anomalies and define why they .pdf
Q1 Discuss three types of accounting anomalies and define why they .pdf
fashionfolionr
 
QUESTION 2727. A profit center is the same as a revenue center.T.pdf
QUESTION 2727. A profit center is the same as a revenue center.T.pdfQUESTION 2727. A profit center is the same as a revenue center.T.pdf
QUESTION 2727. A profit center is the same as a revenue center.T.pdf
fashionfolionr
 

More from fashionfolionr (20)

Discuss the benefits of in-built coding software within the Health I.pdf
Discuss the benefits of in-built coding software within the Health I.pdfDiscuss the benefits of in-built coding software within the Health I.pdf
Discuss the benefits of in-built coding software within the Health I.pdf
 
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
Determine if each system is1. memoryless2. Invertible3. Causal.pdfDetermine if each system is1. memoryless2. Invertible3. Causal.pdf
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
 
According to the Fick equation, what happens to J when X (the distanc.pdf
According to the Fick equation, what happens to J when X (the distanc.pdfAccording to the Fick equation, what happens to J when X (the distanc.pdf
According to the Fick equation, what happens to J when X (the distanc.pdf
 
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
A 14 foot ladder is leaning against a building. If the bottom of the.pdfA 14 foot ladder is leaning against a building. If the bottom of the.pdf
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
 
Briefly discuss operating system, firmware, and utility programs..pdf
Briefly discuss operating system, firmware, and utility programs..pdfBriefly discuss operating system, firmware, and utility programs..pdf
Briefly discuss operating system, firmware, and utility programs..pdf
 
Assume that scores on the LSAT are approximately normally distribute.pdf
Assume that scores on the LSAT are approximately normally distribute.pdfAssume that scores on the LSAT are approximately normally distribute.pdf
Assume that scores on the LSAT are approximately normally distribute.pdf
 
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
All answers must be in your own wordsWhat iswas The Great Law Wh.pdfAll answers must be in your own wordsWhat iswas The Great Law Wh.pdf
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
 
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
 
Write a function prototype for each of the following functions (Jus.pdf
Write a function prototype for each of the following functions (Jus.pdfWrite a function prototype for each of the following functions (Jus.pdf
Write a function prototype for each of the following functions (Jus.pdf
 
Why is white collar crime is so difficult to address with law enforc.pdf
Why is white collar crime is so difficult to address with law enforc.pdfWhy is white collar crime is so difficult to address with law enforc.pdf
Why is white collar crime is so difficult to address with law enforc.pdf
 
What is Eulers number and who is it named after Can you name some.pdf
What is Eulers number and who is it named after Can you name some.pdfWhat is Eulers number and who is it named after Can you name some.pdf
What is Eulers number and who is it named after Can you name some.pdf
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdfUsing C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdf
 
Unless specifically legally permitted, agreements to suppress or eli.pdf
Unless specifically legally permitted, agreements to suppress or eli.pdfUnless specifically legally permitted, agreements to suppress or eli.pdf
Unless specifically legally permitted, agreements to suppress or eli.pdf
 
There are tremendous pressures on selected industrialized countries,.pdf
There are tremendous pressures on selected industrialized countries,.pdfThere are tremendous pressures on selected industrialized countries,.pdf
There are tremendous pressures on selected industrialized countries,.pdf
 
This week we covered Accounting and Payroll liabilities and the diff.pdf
This week we covered Accounting and Payroll liabilities and the diff.pdfThis week we covered Accounting and Payroll liabilities and the diff.pdf
This week we covered Accounting and Payroll liabilities and the diff.pdf
 
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdft Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
 
Stark Company has five employees. Employees paid by the hour receive.pdf
Stark Company has five employees. Employees paid by the hour receive.pdfStark Company has five employees. Employees paid by the hour receive.pdf
Stark Company has five employees. Employees paid by the hour receive.pdf
 
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdfSilas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
 
Q1 Discuss three types of accounting anomalies and define why they .pdf
Q1 Discuss three types of accounting anomalies and define why they .pdfQ1 Discuss three types of accounting anomalies and define why they .pdf
Q1 Discuss three types of accounting anomalies and define why they .pdf
 
QUESTION 2727. A profit center is the same as a revenue center.T.pdf
QUESTION 2727. A profit center is the same as a revenue center.T.pdfQUESTION 2727. A profit center is the same as a revenue center.T.pdf
QUESTION 2727. A profit center is the same as a revenue center.T.pdf
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 

A polynomial may be represented as a linked list where each node cont.pdf

  • 1. A polynomial may be represented as a linked list where each node contains the coefficient and exponent of a term of the polynomial. The polynomial 4 X^3 - 3 X^2 - 5 would be represented as the linked list. Write a program system that reads two polynomials, stores them as linked lists, adds them together, and prints the result as a polynomial. The result should be a third linked list. Travers both polynomials. If a particular exponent value is present in cither of the two polynomials being summed, then it should be present in the answer. If it is present in both polynomials, then its coefficient is the sum of the corresponding coefficient in both polynomials. (If this sum is zero, the term should be deleted). Solution #include #include typedef struct link { int coeff; int pow; struct link * next; } my_poly; void my_create_poly(my_poly **); void my_show_poly(my_poly *); void my_add_poly(my_poly **, my_poly *, my_poly *); int main(void) { int ch; do { my_poly * poly1, * poly2, * poly3; printf(" Create 1st expression "); my_create_poly(&poly1); printf(" Stored the 1st expression"); my_show_poly(poly1);
  • 2. printf(" Create 2nd expression "); my_create_poly(&poly2); printf(" Stored the 2nd expression"); my_show_poly(poly2); my_add_poly(&poly3, poly1, poly2); my_show_poly(poly3); printf(" Add two more expressions? (Y = 1/N = 0): "); scanf("%d", &ch); } while (ch); return 0; } void my_create_poly(my_poly ** node) { int flag; int coeff, pow; my_poly * tmp_node; tmp_node = (my_poly *) malloc(sizeof(my_poly)); *node = tmp_node; do { printf(" Enter Coeff:"); scanf("%d", &coeff); tmp_node->coeff = coeff; printf(" Enter Pow:"); scanf("%d", &pow); tmp_node->pow = pow; tmp_node->next = NULL;
  • 3. printf(" Continue adding more terms to the polynomial list?(Y = 1/N = 0): "); scanf("%d", &flag); //printf(" FLAG: %c ", flag); if(flag) { tmp_node->next = (my_poly *) malloc(sizeof(my_poly)); //Grow the list tmp_node = tmp_node->next; tmp_node->next = NULL; } } while (flag); } void my_show_poly(my_poly * node) { printf(" The polynomial expression is: "); while(node != NULL) { printf("%dx^%d", node->coeff, node->pow); node = node->next; if(node != NULL) printf(" + "); } } void my_add_poly(my_poly ** result, my_poly * poly1, my_poly * poly2) { my_poly * tmp_node; tmp_node = (my_poly *) malloc(sizeof(my_poly)); tmp_node->next = NULL; *result = tmp_node; while(poly1 && poly2) {
  • 4. if (poly1->pow > poly2->pow) { tmp_node->pow = poly1->pow; tmp_node->coeff = poly1->coeff; poly1 = poly1->next; } else if (poly1->pow < poly2->pow) { tmp_node->pow = poly2->pow; tmp_node->coeff = poly2->coeff; poly2 = poly2->next; } else { tmp_node->pow = poly1->pow; tmp_node->coeff = poly1->coeff + poly2->coeff; poly1 = poly1->next; poly2 = poly2->next; } if(poly1 && poly2) { tmp_node->next = (my_poly *) malloc(sizeof(my_poly)); tmp_node = tmp_node->next; tmp_node->next = NULL; } } while(poly1 || poly2) { tmp_node->next = (my_poly *) malloc(sizeof(my_poly)); tmp_node = tmp_node->next;
  • 5. tmp_node->next = NULL; if(poly1) { tmp_node->pow = poly1->pow; tmp_node->coeff = poly1->coeff; poly1 = poly1->next; } if(poly2) { tmp_node->pow = poly2->pow; tmp_node->coeff = poly2->coeff; poly2 = poly2->next; } } printf(" Addition Complete"); } output: Create 1st expression Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff:
  • 6. Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0): Enter Coeff: Enter Pow: Continue adding more terms to the polynomial list?(Y = 1/N = 0):