473,224 Members | 1,436 Online

# 1D array values into a 2D array

I have been breaking my head by taking array[16] and passing it's values to arrayTwo[4][4], I'm trying to use a for loop for this, but it's just driving me crazy...can any body help me.

Thanks.
Jan 29 '06 #1
4 9731
Niheel
2,460 Expert Mod 2GB
Paste your code here; so that we can check it out. Use the CODE tag so that your code displays properly.

Thanks
Feb 3 '06 #2
I got it...thanks for the help anyways...if you still want the code I did, let me know...when i get home I'll post it here.
Feb 3 '06 #3
Niheel
2,460 Expert Mod 2GB
Sure, it would be greatly appreciated. It could help another developer.

Thanks
~ KUB
Feb 3 '06 #4
Ok, I did it a function. that takes 3 parameter. The first is an array called list and listSize is a constant with the value of the 16 elements. Since it's an array, the value is 15.

matrix is the 4 by 4 array that we want to pass the values into.

row is the number of rows.

here is the function.

void matricize(int list[listSize], int matrix[rows][columns], int rows)
{
//INPUT THE VALUES OF ONE-DIMENSION ARRAY INTO THE TWO-DIMENSION ARRAY
int listSize=0;

for (int counter1 = 0; counter1 < rows; counter1++)
{
for (int count=0;count < columns; count++)
{
matrix[counter1][count] = list[listSize];
listSize++;
}
}
}

thanks for you help KUB
Feb 10 '06 #5