Very simple question: I need the steps not the result please.
Background: I am taking very large numbers and storing them in an array. Then I either add or subtract the two. As it is an array I have to do it column by column. I have the addition done. But for the life of me cannot figure out/remember what to when subtracting a larger number from a smaller.
What are the steps in solving this question column by column?
50
-500
-----
EDIT: They are stored in a int[]. Using arrays because it is the assignment requirement.
Just need to understand the logic of subtraction column by column.
I take it that you are representing numbers as arrays of digits. So, for instance, 50 is represented by [5, 0] (or, perhaps more conveniently, [0, 5]). I also assume that you have some way of representing negative numbers (which you will need for subtraction).
You have a couple of options for dealing with subtracting a larger number from a smaller one:
The latter option assumes that your addition algorithm works for mixed-sign arguments and also works regardless of the magnitude of the minuend and subtractend. Both options assume that you have an algorithm for negating a number.
If you have no means of representing negative numbers, then the only thing you can do is signal failure when asked to compute 50 – 500 (since you have no way of representing the result).