Tuesday, July 28, 2009

C programming question on array updating?

data[1,356,862] = {10,20,........,100,0,8}





for (i=o;i%26lt;1,356,862;i++)


{





an alogorithm to get the next 32 elements of an array





Do some math on the 32 elemnts





}





My question is How can I get the next 32 elements , once I am done doing some math on the previous one?


Do I have to shift the whole array evey time? Please advice if there is any short cut.


Thanks

C programming question on array updating?
I don't understand what you are asking exactly. The 'for' loop will allow you to increment the place in the array... so...





for (int i = 0, i %26lt; reallyBigNumber; i++)


{


doSomeMath(data[i]);


}


I dont understand the question... do you want to access the first element and then the 32 elements after it, move on to the second element and access the next 32 elements, thennn go to the nth element and access the 32 elements after it? or do you want to... do something with the first 32 elements, then do something with array[33] through array[65] and so forth?





to do the first senario:





int sum = 0;


float avg = 0;


for (int i = 0; i %26lt; reallyBigNumber, i++)


{


for (int j = 0; j %26lt; 32; i++)


{


sum = data[i + j]


}


avg = sum / 32;


cout %26lt;%26lt; avg %26lt;%26lt; endl;


}





either way, just add another for loop


No comments:

Post a Comment