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: 3637558 • 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!)

Assume we have a computing agent that knows how to do one-digit subtraction where the first digit is at least as large as the second(i.e, we do not end up with a negative number). Thus, our computing agent can do such operations as 7-3=4, 9-1=8, and 5-5=0. It can also subtract a one- digit value from a two-digit value in the range 10-18 as long as the final result has only a single digit. This capability enables it to do such operations as 13-7=6, 10-2=8 and 18-9=9. Using these primitive capabilities, disign an algorithm to do decimal subtraction on two m-digit numbers, where m > or = to t 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

you take a borrow only when you are lesser than the above number this can increase your value by max 10. So even if you subtract, there will be a single digit number left. Hence simple substraction works.

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