How do I sequentially add numbers from different arrays?
Posted: Sat Jan 24, 2009 12:44 pm
So I have a series of arrays (around 65) that I need to add together. But I need to add the respective values while maintaining the original value it was derived from. In other words, this is what I have now:
Each array has a set number of values (31). I need to add the respective values from all the arrays so it looks like this:
So the first value of the array is the sum of itself and the first value from the previous array. And so on 65 times.
I am really confused with how to structure my loops. I think the array itself should have a counted value (array['1-65']) and then the array's values should also be counted (array['1-31']), but I'm not sure how to count both the values within an array and multiple arrays themselves, let alone start adding their respective values.
Am I looking in the right place for how to do this? Or is my approach wrong?
Code: Select all
array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
array(1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,0,-1,1,1,1,1,1,-1,-1,-1,1,1,-1,-1,0,1,0,1,0,0);
array(1,1,1,1,0,-1,-1,1,1,1,0,0,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0);
Code: Select all
array(0,0,0,0,0,0,0,0,...
array(1,-1,-1,-1,-1,-1,-1,-1,1,...
array(2,0,0,0,-1,-1,-1,0,... // notice the first column: 0, 1, 1 becomes 0, 1, 2
I am really confused with how to structure my loops. I think the array itself should have a counted value (array['1-65']) and then the array's values should also be counted (array['1-31']), but I'm not sure how to count both the values within an array and multiple arrays themselves, let alone start adding their respective values.
Am I looking in the right place for how to do this? Or is my approach wrong?