Array Addition??

Hi,

I am just a bit stuck with some array manipulation and was wondering if anyone would be able to help out?

Is it possible to add two arrays??

e.g.

int array1[6] = {0,1,2,3,4,5};
int array2[6] = {1,2,3,4,5,6};

I want the result of array1 + array2 to be a third array {1,3,5,7,9,11}

Does anyone know how this can be done?

THANKS!! :smiley:

Set up a for loop to add the elements one at a time.

array3 = array1 + array2

thanks,
but what i meant to say was is there a way one can make a function which does this? my sketch requires me to add a number of different arrays depending on different situations so a function would be appropriate.
however whenever i try to return an array from this function it never works...

#define ARRAY_LEN 10

void myfunc(void)
{
    int a[ARRAY_LEN] = {0,1,2,3,4,5,6,7,8,9};
    int b[ARRAY_LEN] = {1,3,5,7,9,11,13,15,17,19};
    int sum[ARRAY_LEN];

    add_arrays(ARRAY_LEN,a,b,sum);
}

void
add_arrays(int array_len,int array1[],int array2[],int result[])
{
    int i;

    for (i = 0; i < array_len; ++i)
      result[i] = array1[i] + array2[i];
}

thanks mike ;D

BTW that works because arrays are passed by reference, not by value.