Accepting and displaying Element using 2d array in c program
- #include<stdio.h>
- int main()
- {
- int a[2][2];
- int i, j;
- //Logic to read matrix
- for ( i = 0; i < 2; i++ ) //related to row
- {
- for ( j = 0; j < 2; j++ ) //related to column
- {
- scanf("%d", &a[i][j]);
- }
- }
- for(i = 0; i < 2; i++)
- {
- for(j = 0; j < 2; j++)
- {
- printf("Array Element %d\t",a[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Output
//Entered array Element
1 2
3 4
//Displayed array Element
Array Element 1 Array Element 2
Array Element 3 Array Element 4
Comments