Two dimensional arrays:
1.Two dimensional array is known as matrix.
2.An array with two subscripts is termed as two-dimensional array.
3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements.
2.An array with two subscripts is termed as two-dimensional array.
3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements.
The syntax of declaring a two-dimensional array is :
Data-type array name[row][column];
For reading value :
for(k=0;k<4;k++)
{
for(l=0;l<3;l++)
{
scanf("%d",&a[k][l]);
}
}
For displaying value :
for(k=0;k<4;k++)
{
for(l=0;l<3;l++)
{
printf("%d",a[k][l]);
}
printf("\n");
}
Simple Matrix Program :
#include"stdio.h"
int main()
{
int a[3][3];
int k,l;
printf("Enter the array elements: \n");
for(k=0;k<3;k++) //for reading value//
{
for(l=0;l<3;l++)
{
printf("Enter a[%d][%d] :",k,l);
scanf("%d",&a[k][l]);
}
}
printf("\n\nMatrix are: \n");
for(k=0;k<3;k++) //for displaying value//
{
for(l=0;l<3;l++)
{
printf("%d\t",a[k][l]);
}
printf("\n");
}
}
Output are:
Enter the array elements:
Enter a[0][0] :1
Enter a[0][1] :4
Enter a[0][2] :5
Enter a[1][0] :7
Enter a[1][1] :12
Enter a[1][2] :8
Enter a[2][0] :96
Enter a[2][1] :10
Enter a[2][2] :3
Matrix are:
1 4 5
7 12 8
96 10 3
Comments
Post a Comment