C program for accessing 2-D Array elements

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
int i,j,a[3][3];

// i : For Counting Rows
// j : For Counting Columns

printf("Enter 3*3 Matrix\n");
 for(i=0;i<3;i++)
    {
      for(j=0;j<3;j++)
      {
         scanf("%d",&a[i][j]);
      }
   }

//Print array elements
printf("Your entered matrix is \n");
 for(i=0;i<3;i++)
    {
      for(j=0;j<3;j++)
       {
         printf("%d\t",a[i][j]);
       }
      printf("\n");
   }
}

OUTPUT:

Enter 3*3 Matrix
3 1 2
4 2 1
2 3 4
Your entered matrix is
3       1       2
4       2       1
2       3       4

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.