pleas help me
Write an algorithm to add and multiply two large integers, which cannot be
represented by built-in types.
miracle Kimuli
Edited
by miracle Kimuli
- 2 Contributors
- forum1 Reply
- 10 Views
- 5 Years Discussion Span
- comment Latest Post by Adak
Adak 419
It's an old school type solution, but I used three int arrays. One for each of the two numbers' digits to go into, and one to hold the "carry" value.
Imagine they are stacked up on top of each other. One digit ONLY per element of each array. Any value > 9, puts the "carry value, into the carry array with the proper (next) index.
Work from the one's column (far right hand side), or you can make it a bit easier and reverse the number, and work from the left hand side (so the indices get bigger in the array's as you loop from first to last digit columns.
Start with a small 3 digit number and see which way you prefer and get the logic worked out, before you jump to bigger numbers.
The process is EXACTLY the same as if you were multiplying numbers together by hand, in grade school.
Laying it out first by hand, (pen and paper) a few times, is a worthwhile experience, since we're so used to using calculators all the time.