A 2D ARRAY IS A COLLECTION OF 1D ARRAY. IT IS A COLLECTION OF ROWS AND COLUMNS.
TO PRINT OR ACCESS THE ELEMENTS, WE CAN WRITE AS :-
ROWS - for(i=0;i<4;i++);
{
COLUMNS - for(j=o;j<5;j++);
{
printf("%d",a[i][j]);
}
}
THE OUTER LOOP INDICATES THE NUMBER OF ROWS. WHEREAS THE INNER LOOP INDICATES THE NUMBER OF COLUMNS. TO ACCEPT VALUES FROM THE USER WE CAN USE THE NESTED FOR LOOP AS FOLLOWS :-
ROWS - for(i=0;i<4;i++);
{
COLUMNS - for(j=o;j<5;j++);
{
scanf("%d",a[i][j]);
}
}
TO PRINT OR ACCESS THE ELEMENTS, WE CAN WRITE AS :-
ROWS - for(i=0;i<4;i++);
{
COLUMNS - for(j=o;j<5;j++);
{
printf("%d",a[i][j]);
}
}
THE OUTER LOOP INDICATES THE NUMBER OF ROWS. WHEREAS THE INNER LOOP INDICATES THE NUMBER OF COLUMNS. TO ACCEPT VALUES FROM THE USER WE CAN USE THE NESTED FOR LOOP AS FOLLOWS :-
ROWS - for(i=0;i<4;i++);
{
COLUMNS - for(j=o;j<5;j++);
{
scanf("%d",a[i][j]);
}
}
0 comments: (+add yours?)
Post a Comment