-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolynomial addtion.py
67 lines (34 loc) · 965 Bytes
/
polynomial addtion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# A[] repesent coefficient of first polynomial
# B[] repesent coefficient of Second polynomial
def add(A,B,m,n):
size = max(m,n)
C=[ 0 for i in range(size)]
for i in range(0,m,1):
# each term from first polynomial
C[i]=A[i]
#Add each term of second poly add it to c
for i in range(n):
C[i]+=B[i]
return C
#A function point a poly
def display(poly,n):
for i in range(n):
print(poly[i],end="")
if(i!=0):
print("X ^ ",i,end="")
if(i!=n-1):
print(" + ",end="")
#driver code
if__name__='__main__'
A=[1,2,3,4]
B=[0,7,0,5]
m=len(A)
n=len(B)
print("\n first polynomial is :")
display(A,m)
print("\n Second polynomial is :")
display(B,n)
C=add(A,B,m,n)
size=max(m,n)
print("\n Addition of polynomial :")
display(C,size)