Considering an array a single integer, how to do mathematical operations on it?

here i have an assignment, creating a longInt class and using it to calculate large numbers, i dont have a clue how to manipulate a whole array as a single ineteger. Any help will be appreciated
Just think of it as how you might have done basic addition, subtration, multiplication, etc. in your early years at school. For example, you could have each number in the array hold an integer up to 10 (you can make it larger to make it more efficient, but 10 is the easiest to implement). Then you can iterate over the arrays and perform operations.

For example, for addition, you could have it so that it adds the two 'rightmost' numbers in the array. If they go over 10, it subtracts 10 and adds one to the next value along in the result array (resizing it if necessary). Then you go to the next value in the array, and do the same, so on until one you have reached the end of both arrays (pad on imaginary zero's once one array has finished). I won't write this for you, but hopefully this gives you some ideas on how you might go about doing it.
Thanks, I want to do it myself.
And yes i pretty much got how to do that.
Taking input all the numbers in a single shot, should I do it with a character array and then store the value iteratively to an integer array?
Last edited on
Yes, that would be easiest, considering that it is the only real way of storing a number infinitely large anyway.
Thanks for the help =)
If you do decide to only go up to 10 then I'd suggest making it an array of shorts instead of ints.
@newbieg
Why? Shorts aren't necessarily smaller than integers, integer arithmetic on some processors is faster than short arithmetic. If anything, only going to 10 would be best optimized by using unsigned char.
Ack!
I thought short and char were synonyms, woops. Bad post, sorry.
Topic archived. No new replies allowed.