We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
logic : -
suppose you're asked to multiply 25 with 24..
what toddlers do..
25
* 24
100
50 *
600
what we do...
5*24=120, 0 stays, carry 12... then 2*24+12=60.. hence 600.
this method is called supercarry.
Take an array, use this supercarry method and for every i, print a digit in array[i]. then print the anti-array.
If there are extra zeroes in front of the answer, remove them by using..
for (i = len; i >= 0; i--)
if (a[i] != 0) {
neww = i;
break;
}
for (i = neww; i >= 0; i--)
printf("%d", a[i]);
how your multiplication goes..
n=25.
52
006
00831
006303
etc..
when you print the anti-array
the number prints without any problem...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →
solution of this code in c...
logic : - suppose you're asked to multiply 25 with 24..
what toddlers do..
* 24
100
50 *
600
what we do... 5*24=120, 0 stays, carry 12... then 2*24+12=60.. hence 600. this method is called supercarry. Take an array, use this supercarry method and for every i, print a digit in array[i]. then print the anti-array. If there are extra zeroes in front of the answer, remove them by using..
for (i = len; i >= 0; i--) if (a[i] != 0) { neww = i; break; } for (i = neww; i >= 0; i--) printf("%d", a[i]);
how your multiplication goes..
n=25.
52 006 00831 006303
etc..
when you print the anti-array
the number prints without any problem...