CSE Lab 8
CSE Lab 8
1
Outcomes
Multidimensional arrays
Situations where more than one table is required.
int a[10]={0};
print(“%d”, a[10])
a[i+j*10];
a[i] = b[i++];
Sequential/linear search
Binary search
5 7 1 4 2 3
5 1 4 2 3 7
1 4 2 3 5 7
1 2 3 4 5 7
1 2 3 4 5 7
You can use additional braces to indicate when rows start and
end, but you don’t have to do that.
Initialization
• int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; 1 2
• Initializers grouped by row in braces 3 4
Referencing elements
• Specify row, then column
• printf( "%d", b[ 0 ][ 1 ] );
// C = A + B
for (i=0; i<NUM_ROWS; i++)
{
for (j=0; j<NUM_COLS; j++)
{
C[i][j] = A[i][j] + B[i][j];
}
}
...
...
// display C
for (i=0; i<NUM_ROWS; i++)
{
for (j=0; j<NUM_COLS; j++)
{
printf(“%d”,C[i][j]);
}
printf(“\n”);
}
printf(“\n”);
...