Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
792 views
in RTU/BTU B.Tech(CSE-III Sem) DSA LAB by Goeduhub's Expert (7.6k points)
Represent a 2-variable polynomial using array. Use this representation to implement addition of polynomials.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Ques . Write a program to show addition of two polynomial

Answer : 

Example : 

A[] = {2, 1, 1, 6} 
B[] = {1, 2, 4} 
sum[] = {3, 3, 17, 6}

A[] : 2 + 1x^1 + 1x^2 + 6x^3
B[] : 1 + 2x^1 + 4x^2 
Sum[] : 3 + 3x^1 + 17x^2 + 6x^3

Program : 

def add(A, B, m, n): 

    size = max(m, n); 

    sum = [0 for i in range(size)] 

    for i in range(0, m, 1): 

        sum[i] = A[i] 

    for i in range(n): 

        sum[i] += B[i] 

    return sum

def printPoly(poly, n): 

    for i in range(n): 

        print(poly[i], end = "") 

        if (i != 0): 

            print("x^", i, end = "") 

        if (i != n - 1): 

            print(" + ", end = "") 

A = [5, 0, 10, 6] 

B = [1, 2, 4] 

m = len(A) 

n = len(B) 

print("enter First polynomial is") 

printPoly(A, m) 

print("", end = "") 

print("\n enter Second polynomial is") 

printPoly(B, n) 

print("", end = "") 

sum = add(A, B, m, n) 

size = max(m, n) 

print("\nsum polynomial is") 

printPoly(sum, size)

Output : 

enter First polynomial is

5 + 0x^ 1 + 10x^ 2 + 6x^ 3

enter Second polynomial is

1 + 2x^ 1 + 4x^ 2

sum polynomial is

6 + 2x^ 1 + 14x^ 2 + 6x^ 3

For more Rajasthan Technical University CSE-III Sem DSA Lab Experiments  CLICK HERE


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...