Skip to content

Commit 3ffc59e

Browse files
authored
Initial File
Multiply strings
1 parent 3fec4f9 commit 3ffc59e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Multiply strings

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def multiply_str(str1,str2):
2+
len1=len(str1)
3+
len2=len(str2)
4+
5+
str1 = list(map(int,reversed(str1)))
6+
str2 = list(map(int, reversed(str2)))
7+
8+
res = [0 for i in range(len1+len2)]
9+
10+
for j in range(len2):
11+
for i in range(len1):
12+
13+
res[i+j] = res[i+j]+str1[i]*str2[j]
14+
res[i+j+1] = res[i+j+1] +res[i+j]//10 #carry
15+
res[i+j] = res[i+j] % 10
16+
17+
i=len(res)-1
18+
while(res[i]==0 and i>0):
19+
i=i-1
20+
21+
return "".join(map(str,res[:i+1][::-1]))
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
str1="78"
35+
str2="57"
36+
print(multiply_str(str1,str2))

0 commit comments

Comments
 (0)