Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be given two unsigned whole numbers a m-1 a m-2 ....a 0 and b m-1 b m-2

ID: 3637498 • Letter: Y

Question

You will be given two unsigned whole numbers am-1 am-2 ....a0 and bm-1 bm-2 ....b0.  Your algorithm must compute the value cm-1 cm-2 ....c0, the difference of these two values. (am-1 am-2 ....a0 )-(bm-1 bm-2 ....b0 ) = cm-1 cm-2 ....c0 

You may assume that the top number ( am-1 am-2 ....a0 ) is greater than or equal to the bottom number (bm-1 bm-2 ....b0 ) so that the result is not a negative value. However, do not assume that each individual digit ai is greater than or equal to bi. If the digit on the bottom is larger than the digit on the top, then you must implement a borrowing scheme to allow the subtraction to continue. (Caution: it may have been easy to learn subtraction as a first grader, but it is devilishly difficult to tell a computer how to do it!)

Explanation / Answer

It's actually not nearly as hard as it sounds. The key is to realize how borrowing works. If you need to borrow one from a[i+1], you need to add TEN to a[i].

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote