Lesson-18, 19, 20
Lesson-18, 19, 20
1
Lesson – 18
⮚ 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
⮚ You can use additional braces to indicate when rows start and
end, but you don’t have to do that.
{3,15,27,6}, 3 15 27 6
{14,25,2,10} 14 25 2 10
};
⮚ Initialization
• int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; 1 2
⮚ 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”);
...