Sum all odd array elements?

This is a discussion on Sum all odd array elements? within the C Programming forums, part of the General Programming Boards category; I was wondering how one would sum up all of the even elements of an array into one sum and ...

Sum all odd array elements?

I was wondering how one would sum up all of the even elements of an array into one sum and all of the odd elements of an array into another.

Let's say the array is "double a[]" and the size is "n".

I could first have to figure out if the array is either even or odd by doing a "&#37;2 == 0" IF statement, but I don't know if that is necessary.

I'm guessing there could be two possible for loops with something in them like "a[n+2]" to skip every other value, and only go to as many values as the IF statement would retrieve.

The details are a bit fuzzy for me to think out logically, on paper, or in C. If someone could tell me a basic run down of how I should go about doing it or a for loop or two written out showing me how to skip odd/even values in an array that would be awesome.

If the details are fuzzy, there's nothing you can do but write things out on a piece of paper until they're clear. I can think of five different ways to do this off the top of my head, so you're going to have to decide what you want to do.

Yeah, writing things out on paper usually works pretty well for me, but sometimes I just get stumped. I know I want to do it with a for loop, but I don't know the correct way to write it. I'm not that great on pointing out what is or isn't legal. I'd like to write:

for( 1st even number in array; 1st even number until max value in array; add two to array, skipping the odd number)

Hopefully you know what the 1st even number in the array is. The constraint of even number in the second part is useless. The third part is redundant, as adding two to array (I assume you mean the array index) by definition skips the odd number.