CS246 Homework 3: pointers and arrays
Due: Monday, Feb 20, 2012 - 2:30pm (before class)
What to hand in:
- Include a README file: if your program behaves in anyway differently from specified, or there are bugs you'd like to point my attention to, this is the place for it.
- Paper print out and electronic tar file copied to /home/dxu/submissions/cs246 as usual.
Big int [100pts]
In this program we will simulate very large integers with arrays in the following way: digits are stored into the array starting with the least significant. That is, given an integer 123, it is stored with 3 at index 0, 2 and index 1 and 1 at index 2.
Write the following functions:
- int plus(int *x, int sizex, int *y, int sizey, int *res), which takes two arrays x and y and their respective sizes, performs addition and stores the result into the array res. Return the number of digits of the resulting sum (i.e. nubmer of digits stored into res).
- int mult(int *x, int sizex, int *y, int sizey, int *res), which takes two arrays x and y and their respective sizes, performs multiplication and stores the result into the array res. Return the number of digits of the resulting product (i.e. nubmer of digits stored into res).
Copy the framework code ~dxu/handouts/cs246/bigint_frame.c and use it as a starting point. A main complete with test cases as well as a print function have been provided for you. Additional requirements:
- Use pointer notation to address the arrays whenever possible.
- Use the existing #define for all size related operations.