I've ran into a seemingly simple problem but I can't figure out how to do it. I want to fill the second column in an array of 32 rows and 4 columns like this: 1,1,2,2,3,3,...,16,16. And, I want to use an already-existing loop where the counter goes from 0 to 15. So each time I want to write on two elements without that element being overwritten in it's following loop. I did this: array[4*i+1]=i+1; array[4*i+5]=i+1; But then array[4*i+5] is being overwritten in the next loop. How should I do this?
You actually want your math inside the array to be as follows:
array[8*i+1]=i+1;
array[8*i+5]=i+1;
since you are actually moving through 2 rows x 4 columns = 8 per iteration
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.