Problem Description Link
Algorithm:
Algorithm:
To solve this problem you can use array and get input in
string result is a int type array and a and b is char type array.
For example:
We multiply (123 * 345) so result is 42435
We multiply 123 by 345
a[]
1
|
2
|
3
|
b[]
3
|
4
|
5
|
Using formula:
L+=1;
temp=(b[i]-48)*(a[j]-48)+carry+result[l];
result[l]=temp%10;
carry=temp/10;
At first set (0) all element of array.
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
Then multiply 123 by 5
5
|
3
|
6
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
Then multiply 123 by 4
5
|
3
|
5
|
5
|
0
|
0
|
0
|
0
|
0
|
0
|
Finally multiply 123
by 3
5
|
3
|
4
|
2
|
4
|
0
|
0
|
0
|
0
|
0
|
Print right to left 42435
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience