Lab 4 - Due June 16: Phase 1 - From The Homework - Introduction To Arrays
Lab 4 - Due June 16: Phase 1 - From The Homework - Introduction To Arrays
where number1, number2 and totalnumber are each printed from OutputNumber function (i.e.
you will have to call the OutputNumber function 3 times one for each of the arrays). The
output calls should be from the main program.
Therefore, you need to write two additional functions:
AddArrays is a function that should have three char arrays as parameters. The first two arrays
are those you have input. The third array will be empty on the call and should return the sum of
the first two arrays
So if array 1 had the chars
1 2 4
and array 2 had
2 3 6
the total array should contain (it MUST be chars)
3 5 0 1
Your program should also take into account for overflow from carry overs. For example if Array1
was
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
And array 2 was:
5
2
4
4
The output array would overflow because there are not 21 elements available to handle the high
order carry.
HINT: HOW TO CONVERT CHAR TO INT
If you remember the ASCII table the bit pattern for the ASCII char 0 is 00110000, the bit pattern
for the char 1 is 00110001. To convert 0 to the int 0 if you subtract 0 from 0 that performs
the subtraction 00110000 00110000 which leaves the bits as 00000000 which is the integer
value of 0. If I subtract 0 from 1 I have 00110001 00110000 which leaves me with 00000001
which is the int value of 1. Therefore, your logic to convert a char to an int is Array[i] 0.
If you subtract 0 to convert a char to an int what would you do to convert an int back to a char?
OutputNumber is a function that accepts an array as input and outputs the array in reverse order
(i.e. the number ) without the leading 0s for the number. Thus if the array passed in had
5
2
4
4
0
The output would be
4425
Addition Overflow
99999999999999999999 + 1 = ERROR:
Would you like to add two more numbers (y/n)? n
Addition Overflow