Assuming you want to add 12 to the 45 (last two indices of the first array) I would go about it like so.
Find # of indices for smaller array. for loop to keep adding as long as counter is less than number of indices in small array. Add contents of last index in small array to last index in big array. Reloop, if counter is less than number of indices, add contents of second to last index of small array to second to last index in big array.
You can also take the smaller array and put it into an array the same size as the bigger one and pad it with zeroes in the front. That way the actual operation won't have to be changed.
Mathematics:
The sum A+B of two m-by-n matrices A and B is calculated entrywise:
(A + B)i,j = Ai,j + Bi,j, where 1 ≤ i ≤ m and 1 ≤ j ≤ n.
So you can't add them if they don't have the same m-by-n size.
But something is different in programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main()
{
int array1[] = {2, 3, 4, 5}; //array1[0]=2,array1[1]=3,array1[2]=4,array1[3]=5
int array2[] = {1, 2}; //array2[0]=1,array2[1]=2
int array3[7];
array3[0]=array1[0]+array2[0];
array3[1]=array1[1]+array2[1];
array3[2]=array1[2];
array3[3]=array1[3];
//Or you can do something...
return 0;
}
So, if array2 is meant to be 12 and array1 is meant to be 2345, then I'd say the easiest solution is:
1 2 3 4 5 6 7 8 9 10 11 12 13
int size1 = sizeof(array1[])/sizeof(array1[0]);
int size2 = sizeof(array2[])/sizeof(array2[0]);
int sum = 0;
for (i = max(size1, size2); i > 0; i--)
{
if (size1>0)
sum += array1[size1]*pow(10,size1);
if(size2>0)
sum+= array2[size2]*pow(10,size2);
size1--; size2--;
}
Stewbond: using a single int to represent the number defeats the point of having a bignum lib, though. The whole idea is an int won't be large enough to hold the number.
But that doesn't matter because the odds of this being for a bignum lib are doubtful. If that were the case he wouldn't have asked this:
2 3 4 5
+ 1 2
______
=???
The fact that he doesn't know what the sum would be is the problem, here. He's trying to do something that makes no sense. It's like he's asking "how do you add trees and milk together?". Yeah we can come up with an answer if we really want, but the question is pointless.