Cho hai đa thức A và B viết chương trình cộng hai đa thức A và B đã cho bằng Python

Giả sử, ta có hai đa thức và ta phải tìm phép cộng của hai đa thức đó. Các đa thức phải được biểu diễn dưới dạng danh sách liên kết; . Mỗi nút danh sách được liên kết sẽ chứa giá trị hệ số, giá trị công suất và con trỏ tới nút danh sách được liên kết tiếp theo. Ta phải trả về một danh sách liên kết thứ ba là phép cộng của hai đa thức danh sách liên kết

Vì vậy, nếu đầu vào giống như

1x^1 + 1x^2 = 0 và 2x^1 + 3x^0 = 0,

thì kết quả sẽ là 3x^1 + 1x^2 + 3x^0 = 0

Để giải quyết vấn đề này, chúng tôi sẽ làm theo các bước sau -

  • đồ giả. = một nút đa thức mới

  • nút. = một nút đa thức mới

  • trong khi poly1 và poly2 không trống, hãy làm

    • nếu công suất của poly1 > công suất của poly2 thì

      • tiếp theo của nút. = poly1

      • nút. = poly1

      • poly1. = tiếp theo của poly1

    • ngược lại khi công suất của poly1 < công suất của poly2 thì

      • tiếp theo của nút. = poly2

      • nút. = poly2

      • poly2. = tiếp theo của poly2

    • nếu không thì,

      • coef. = hệ số poly1 + hệ số poly2

      • nếu coef khác không, thì

        • poly1. = tiếp theo của poly1

        • poly2. = tiếp theo của poly2

  • tiếp theo của nút. = poly1 hoặc poly2

  • quay trở lại bên cạnh hình nộm

Chúng ta hãy xem triển khai sau đây để hiểu rõ hơn -

Thí dụ

class polynomial:
def __init__[self, coeff = 0, pow = 0, nxt = None]:
   self.coefficient = coeff
   self.power = pow
   self.next = nxt
def create_poly[expression]:
   head = None
   for element in expression:
      if head == None:
         head = polynomial[element[0], element[1]]
      else:
         temp = head
      while temp.next != None:
         temp = temp.next
         if temp.next == None:
            temp.next = polynomial[element[0], element[1]]
            return head
def show_poly[head]:
   temp = head
   while temp.next != None:
      print[str[temp.coefficient] + 'x^' + str[temp.power], end = ' + ']
      temp = temp.next
      if temp.next == None:
         print[str[temp.coefficient] + 'x^' + str[temp.power], end=' = 0']
def solve[poly1, poly2]:
   dummy = node = polynomial[]
   while poly1 and poly2:
      if poly1.power > poly2.power:
         node.next = node = poly1
         poly1 = poly1.next
      elif poly1.power < poly2.power:
         node.next = node = poly2
         poly2 = poly2.next
      else:
         coef = poly1.coefficient + poly2.coefficient
      if coef: node.next = node = polynomial[coef, poly1.power]
         poly1 = poly1.next
         poly2 = poly2.next
         node.next = poly1 or poly2
   return dummy.next
poly1 = create_poly[[[1,1], [1,2]]]
poly2 = create_poly[[[2,1], [3, 0]]]
poly3 = solve[poly1, poly2]
show_poly[poly3]

Đầu vào

poly1 = create_poly[[[1,1], [1,2]]]
poly2 = create_poly[[[2,1], [3, 0]]]

đầu ra

3x^1 + 1x^2 + 3x^0 = 0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
5
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
7
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 // Simple C++ program to add two polynomials1

// Simple C++ program to add two polynomials2

// Simple C++ program to add two polynomials3______3_______0 // Simple C++ program to add two polynomials5

// Simple C++ program to add two polynomials3_______3_______0 // Simple C++ program to add two polynomials8// Simple C++ program to add two polynomials9

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0#include 1

 

// Simple C++ program to add two polynomials3_______264_______4

// Simple C++ program to add two polynomials3_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 #include 9

using0____272_______1

 

// Simple C++ program to add two polynomials3____272_______4

// Simple C++ program to add two polynomials3_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 using9

namespace0namespace1

 

// Simple C++ program to add two polynomials3______3_______6 namespace5

namespace6

 

namespace8

namespace9 std;0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 std;2
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 // Simple C++ program to add two polynomials1

// Simple C++ program to add two polynomials2

std;6_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 using9

std;6______257_______2

namespace0 4

namespace0 6  7

 8_______265_______9// A utility function to return maximum of two integers0 // A utility function to return maximum of two integers1

namespace0 6 // A utility function to return maximum of two integers4

namespace0 9// A utility function to return maximum of two integers7// A utility function to return maximum of two integers8

std;6_______281_______6

namespace6

 

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
03

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
05

// Simple C++ program to add two polynomials2

std;6______3_______08

std;6______3_______0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
11

 

std;6______3_______14

std;6______3_______0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
17

std;6_______3_______0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
20
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
21
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
22
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
21
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
24

std;6_______3_______0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
27
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
21_______3_______29
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
21
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
31

 

std;6_______265_______9

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
35// A utility function to return maximum of two integers8

std;6______3_______38

std;6_______265_______9

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
41// A utility function to return maximum of two integers8

std;6______3_______44

 

std;6______3_______0

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
48

std;6______3_______0 // Simple C++ program to add two polynomials5

 

std;6_______265_______9

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
55// A utility function to return maximum of two integers8

std;6______3_______58

 

std;6______3_______6

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
62

namespace6

Java

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
64

 

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
66
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
67

 

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
69

std;6_______3_______71

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
1
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
77

 8_______3_______6

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
80

std;6_______281_______6

 

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
84

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
85

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
86

std;6_______3_______71

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
90_______3_______0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
5
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
7
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
77

 8_______3_______0 // Simple C++ program to add two polynomials5

 8_______3_______0

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
04// Simple C++ program to add two polynomials9
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0#include 1

 

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
09

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
14
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
16

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17using1

 8_______281_______6

 

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
22

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
14
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
29

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace1

 8_______281_______6

 

 8_______3_______6 namespace5

std;6_______281_______6

 

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
41

std;6_______3_______71 namespace9 std;0_______3_______0 std;2

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
77

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
14
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
29

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17_______4_______58

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17 6
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
61
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
63

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
64
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
65// A utility function to return maximum of two integers0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
67

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace6

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17 6
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
72
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
73
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
63

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
64
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
65// A utility function to return maximum of two integers7
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace6

 8_______281_______6

std;6_______281_______6

 

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
86

std;6_______4_______88

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
71 namespace9
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
91

 8_______4_______93

 8_______3_______0

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
96
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
97
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials01
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials03// Simple C++ program to add two polynomials04

 

 8_______257_______07

 8_______3_______0 // Simple C++ program to add two polynomials10

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
73
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials13
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials15// Simple C++ program to add two polynomials04

 8_______3_______0 // Simple C++ program to add two polynomials19

 8_______3_______0 // Simple C++ program to add two polynomials22

 8_______257_______24// Simple C++ program to add two polynomials25

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______38

 8_______257_______24// Simple C++ program to add two polynomials31

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______44

 8_______3_______0 // Simple C++ program to add two polynomials37

 8_______3_______0 // Simple C++ program to add two polynomials5

 8_______257_______24// Simple C++ program to add two polynomials43

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______58

 

std;6_______281_______6

namespace6

/div>

Python3

// Simple C++ program to add two polynomials51

// Simple C++ program to add two polynomials52

 

// Simple C++ program to add two polynomials54

// Simple C++ program to add two polynomials55

 

// Simple C++ program to add two polynomials57

// Simple C++ program to add two polynomials58

// Simple C++ program to add two polynomials59

// Simple C++ program to add two polynomials60 // Simple C++ program to add two polynomials61

 

std;6_______257_______64// Simple C++ program to add two polynomials65 // Simple C++ program to add two polynomials66// Simple C++ program to add two polynomials67

std;6_______257_______69 // Simple C++ program to add two polynomials65 // Simple C++ program to add two polynomials71

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15 #include 6 // Simple C++ program to add two polynomials74// Simple C++ program to add two polynomials75 // Simple C++ program to add two polynomials76// Simple C++ program to add two polynomials77

 

std;6_______257_______80

using0

std;6_______264_______6 // Simple C++ program to add two polynomials74_______257_______75 // Simple C++ program to add two polynomials76#include 7

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15// Simple C++ program to add two polynomials89
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
73// Simple C++ program to add two polynomials91

 8_______257_______69// Simple C++ program to add two polynomials94// Simple C++ program to add two polynomials65 // Simple C++ program to add two polynomials96

 

std;6_______257_______99

std;6_______264_______6 // Simple C++ program to add two polynomials74// Simple C++ program to add two polynomials75 // Simple C++ program to add two polynomials76#include 05

 8_______257_______69// Simple C++ program to add two polynomials94#include 09// Simple C++ program to add two polynomials65 #include 11

 

std;6______3_______6 // Simple C++ program to add two polynomials69

 

#include 17

// Simple C++ program to add two polynomials60 #include 19

std;6_______264_______6 // Simple C++ program to add two polynomials74// Simple C++ program to add two polynomials75 // Simple C++ program to add two polynomials76#include 05

 8_______264_______27#include 28// Simple C++ program to add two polynomials65 #include 30

 8_______265_______6 #include 33// Simple C++ program to add two polynomials65

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15// Simple C++ program to add two polynomials91

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17#include 27#include 7// A utility function to return maximum of two integers0#include 41// Simple C++ program to add two polynomials65 #include 30

 8_______265_______6 #include 33// Simple C++ program to add two polynomials65 #include 48#include 49

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
73// Simple C++ program to add two polynomials91

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17#include 27#include 7// A utility function to return maximum of two integers7#include 56// Simple C++ program to add two polynomials65 #include 30

 

#include 60

 6 #include 62// Simple C++ program to add two polynomials65// Simple C++ program to add two polynomials65 #include 65#include 66

using0

std;6_______264_______69

std;6______264_______71

std;6_______264_______73____257_______65 // Simple C++ program to add two polynomials71

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
97
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
15_______4_______98// Simple C++ program to add two polynomials01
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials03#include 83

 

std;6_______264_______69

std;6_______264_______88

std;6_______264_______90// Simple C++ program to add two polynomials65 // Simple C++ program to add two polynomials71

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
73
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials13
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98// Simple C++ program to add two polynomials15#include 83

std;6_______272_______00// Simple C++ program to add two polynomials65 using02using03

std;6_______264_______48____257_______65 using02using08

 

std;6_______264_______27____264_______7// Simple C++ program to add two polynomials25using14

std;6______272_______16

std;6_______264_______27#include 7using20#include 56// Simple C++ program to add two polynomials65 #include 30

std;6_______264_______27#include 7using27using14

std;6______272_______30

std;6_______264_______27#include 7using20#include 56// Simple C++ program to add two polynomials65 #include 30

std;6_______257_______69 // Simple C++ program to add two polynomials65 using41

std;6_______257_______64____257_______65 // Simple C++ program to add two polynomials66using46

 

std;6_______264_______27____264_______7using51using14

std;6_______290_______0// Simple C++ program to add two polynomials69using56

using0

using58

using59

C#

using60

using using62

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
66
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
67

 

std;6______3_______69

std;6_______3_______71

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
1
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 using75

std;6______257_______2

 8_______3_______6

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
80

std;6_______281_______6

 

std;6______3_______84

std;6______3_______85

std;6______3_______86

std;6_______3_______71

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
90_______3_______0using95
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0using97
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
3
add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 // Simple C++ program to add two polynomials1

std;6______257_______2

 8_______3_______0 // Simple C++ program to add two polynomials5

 8_______3_______0namespace09// Simple C++ program to add two polynomials9

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0#include 1

 

 8_______4_______09

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 namespace20

 8_______257_______2

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17using1

 8_______281_______6

 

 8_______4_______22

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 namespace34

 8_______257_______2

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace1

 8_______281_______6

 

 8_______3_______6 namespace5

std;6_______281_______6

 

std;6______4_______41

std;6_______3_______71 namespace9 std;0_______3_______0namespace55

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 namespace57

std;6______257_______2

 8_______264_______6 #include 7

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
0 namespace34

 8_______257_______2

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace68

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17 6 namespace71

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17// Simple C++ program to add two polynomials2

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
64namespace75// A utility function to return maximum of two integers0
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
67

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace6

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17_______265_______6 namespace82

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17// Simple C++ program to add two polynomials2

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
64namespace75// A utility function to return maximum of two integers7
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17namespace6

 8_______281_______6

std;6_______281_______6

 

std;6______281_______97

std;6_______4_______88

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
71 namespace9 std;02

std;6______257_______2

 8_______290_______06

 8_______290_______08

 8_______3_______0std;11

 

 8_______290_______06

 8_______290_______16

 8_______3_______0std;19

 8_______3_______0 std;22

 8______3_______0 std;25

 8_______290_______27// Simple C++ program to add two polynomials25

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______38

 8_______290_______27// Simple C++ program to add two polynomials31

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______44

 8_______3_______0std;40

 8_______3_______0 // Simple C++ program to add two polynomials5

 8_______290_______27// Simple C++ program to add two polynomials43

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 8_______3_______58

 

std;6_______281_______6

namespace6

 

std;55

std;56

PHP

std;57

std;58

 

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
9

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
0

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
1

std;63 std;64_______290_______65

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;67
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;69
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;71using14

// Simple C++ program to add two polynomials2

std;6_______290_______75 std;76std;69

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;71
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

std;6_______290_______82 // Simple C++ program to add two polynomials65std;84std;85std;75std;87

using0

std;6_______264_______4

std;6_______264_______6 #include 7std;94 std;95std;94 std;97std;69// A utility function to return maximum of two integers8std;94 01

 8_______290_______82// Simple C++ program to add two polynomials71std;94 06std;65// Simple C++ program to add two polynomials71std;94 10

using0

std;6______272_______4

std;6_______264_______6 #include 7std;94 std;95std;94 std;97std;71// A utility function to return maximum of two integers8std;94 01

 8_______290_______82// Simple C++ program to add two polynomials71std;94 29std;67// Simple C++ program to add two polynomials71std;94 10

using0

std;6_______3_______6 std;82// A utility function to return maximum of two integers8

namespace6

 

namespace8

std;63 std;0 44

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;71using14

// Simple C++ program to add two polynomials2

std;6_______264_______6 #include 7std;94 std;95std;94 std;97std;71// A utility function to return maximum of two integers8std;94 01

std;6______257_______2

 8_______265_______63  44// Simple C++ program to add two polynomials71std;94 10

________265 _______8_______265 ______6 #include 7std;94 ________265 _______72

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
17 63 // A utility function to return maximum of two integers0  76std;94// A utility function to return maximum of two integers8

________265 _______8_______265_______6 #include 7std;94 ________265 _______83 std;71  85

 8_______265_______63 // A utility function to return maximum of two integers7// A utility function to return maximum of two integers8

std;6_______281_______6

namespace6

 

 94

 

 96

 97

std;65 // Simple C++ program to add two polynomials65// A utility function to return maximum of two integers00// A utility function to return maximum of two integers01

 

std;06

// A utility function to return maximum of two integers04

std;67 // Simple C++ program to add two polynomials65// A utility function to return maximum of two integers00// A utility function to return maximum of two integers08

std;69 // Simple C++ program to add two polynomials65// A utility function to return maximum of two integers11#include 7std;65

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

std;71 // Simple C++ program to add two polynomials65// A utility function to return maximum of two integers11#include 7std;67

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 

 63

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
35// A utility function to return maximum of two integers8

std;0_______290_______65

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;69
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 63

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
41// A utility function to return maximum of two integers8

std;0_______290_______67_______4_______98std;71

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 

std;82 // A utility function to return maximum of two integers40std;65

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;67
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;69
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;71
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

std;75 std;76std;69

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;71
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 

 63

add[A[0..m-1], B[0..n01]]
1] Create a sum array sum[] of size equal to maximum of 'm' and 'n'
2] Copy A[] to sum[].
3] Travers array B[] and do following for every element B[i]
          sum[i] = sum[i] + B[i]
4] Return sum[].
55// A utility function to return maximum of two integers8

std;0_______290_______82

First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
98std;75
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3
78

 

// A utility function to return maximum of two integers65

// A utility function to return maximum of two integers66


đầu ra.
First polynomial is
5 + 0x^1 + 10x^2 + 6x^3
Second polynomial is
1 + 2x^1 + 4x^2
Sum polynomial is
6 + 2x^1 + 14x^2 + 6x^3

Độ phức tạp về thời gian của thuật toán và chương trình trên là O[m+n] trong đó m và n là bậc của hai đa thức đã cho

Cách cộng hai đa thức bằng thuật toán?

Bước 1. lặp xung quanh tất cả các giá trị của danh sách được liên kết và làm theo bước 2 & 3. Bước 2. nếu giá trị của số mũ của một nút. tốt hơn là sao chép nút này sang nút kết quả và hướng tới nút tiếp theo. Bước 3. nếu các giá trị của cả hai số mũ của nút giống nhau, hãy thêm các hệ số và sau đó sao chép giá trị đã thêm bằng nút vào kết quả

Làm thế nào để thêm hai đa thức trong c?

số hạng của đa thức bậc nhất giảm đi 1 và chỉ số dưới 'i' cũng tiến lên 2. Nếu điều kiện này sai, thì bậc của tổng c[k] trở thành b[j] và c[k+1]=b[j+1]. The no. of terms of second polynomial gets reduced by 1 and the subscript 'j' is moved forward by 2.

Chủ Đề