def add(A, B, a, b):
size = max(a, b)
sum = [0 for i in range(size)]
for i in range(0, a, 1):
sum[i] = A[i]
for i in range(b):
sum[i] += B[i]
return sum
def printPolynomial(poly, b):
for i in range(b):
print(poly[i], end="")
if (i != 0):
print("x^", i, end="")
if (i != n - 1):
print(" + ", end="")
# Main Funtion
if __name__ == '__main__':
A = [5, 0, 10, 6]
B = [1, 2, 4]
a = len(A)
b = len(B)
print("Polynomial 1:")
printPolynomial(A, a)
print("\n", end="")
print("Polynomial 2:")
printPolynomial(B, b)
print("\n", end="")
sum = add(A, B, a, b)
size = max(a, b)
print("Answer:")
printPolynomial(sum, size)
Comments
Leave a comment