I'm looking for the best way to search through multiple arrays.

For example, I have 4 arrays: A1[8], A2[8], A3[8], and A4[8].

I want to search through all 4 arrays only for the first 4 positions to see if there is a '1'. If so, I'll store the number of occurrences of 1 in a counter variable.

I also want to search the last 4 positions for a 1 also, and add the number of 1 occurrences to another counter variable.

Now, I think I have this down pat. However, I have to do this for every single array and it gets ugly. For my post I used only 4 arrays, but I have 10 in my code. It wastes so much space.

What I'm essentially doing is:

So if A1[8] = {0, 1, 1, 0, 0, 0, 0, 1}, the result will be:Code:for (int i = 0; i <= 3; i++){ for (int j = 4; j <= 8; j++){ if (A1[i] = 1) first_grp = first_count + 1; if (A1[j] = 1) sec_grp = second_count + 1; } }

first_grp = 2

sec_grp = 1

That is for just ONE array. I have 10 of those code blocks in my code right now.

Is there a way to shorten this?

Thanks.