Question: One way to represent a very large integer (one that won't fit into a variable of type short, int, or even long) is to use

One way to represent a very large integer (one that won't fit into
a variable of type short, int, or even long) is to use an array.
The array is of type int, so each element in the array can hold an
integer -- we will store just one digit of our number per array element.
So if a user entered 2375, it might be stored as
--------------------------
| 2 | 3 | 7 | 5 | ... |
--------------------------
(Note that we may want to actually store it right justtified, with
leading 0's on the left, or maybe in reverse order -- but it is a
requirement of this program that you get the digits of the number
from the user 1 at a time, and store them 1 at a time, 1 per array element.)
You should get a number (into an array) using a function called GetNumber.
Keep track of how big it is, if need be. Only allow digits 0-9, no
negatives.)
(you'll call it twice, to get 2 numbers to work with.)
Then call another function called AddNumbers. It takes the 2 numbers and
creates another number (stored in another array) that is the sum of
the 2 given numbers. It should also give back a piece of info that is
boolean (true/false) -- is the 3rd number "valid" ? (no if the addition
causes overflow -- it's too big to fit in an array we use.)
Then call another function called SubNumbers. It takes the 2 numbers and
subtracts them (first minus second.) It gets back to the calling function
the result (and a boolean telling if it is/isn't valid -- if it underflows --
the subtraction would yield a negative, the boolean is false, otherwise
it is true.)
The main function should print out the results (or call a PrintResults
function if you like.)
Allow the user to run for multiple datasets, as usual.
Note that you MUST use functions for GetNumber, AddNumbers, and SubNumbers.
Any other functions are optional -- write them if you feel they help
make this easier.
Make your physical array size 10. (It needs to be exactly 10 to make
the data below, in some instances, meaningful with respect to testing
underflow/overflow.)
-------------------------------------------------------------------------
Data to test/run (note that I'm listing the numbers as multi-digit here,
but they MUST be input 1 digit at a time, and stored 1 digit per array
element.)
9999999999
1
1234567899
8765432101
8765432101
1234567899
2468357955
8000000001
1000000000
1
1000
1
756
437

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!