How two dimensional arrays are initialized?
1. Initialization at design time: In this design techniques data element are stored in to the array at the time of declaration of the array. The elements of each row and each column are represented within the pair of flower brackets.
Example :
int array[3][3]={51,23,75,43,97,32,57,18};
2. Initialization of the array at the time of execution: In this design techniques input data in to two dimensional array, two for loops are used foe every value of the outer loop index. The inner loop is executed a specified number of times.
Example :
int array[5][4];
for(i=0; i<5; i++)
for(j=0; j<4; j++)
scanf(“%d”,&array[i][j]);
How do you print a matrix?
A two dimensional array can be printed as follows:
int a[3][4];
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: