Right Click to Search

Thursday, December 31, 2024

Accessing 2-D Array Elements In C Programming


Accessing Array Elements
  1. To Access Every 2-D Array we requires 2 Subscript variables.
  2. i - Refers the Row number
  3. j - Refers Column Number
  4. a[1][0] refers element belonging to first row and zeroth column
Accept & Print 2x2 Matrix from user
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3];
/*  i = For Counting Rows
    j = For Counting Columns  */
/* Accept 9 elements from user */
for(i=0;i<3;i++)
   for(j=0;j<3;j++)
   {
    printf("\nEnter the a[%d][%d] = ",i,j);
    scanf("%d",&a[i][j]);
   }  
/* Print 9 elements */
for(i=0;i<3;i++)
   {
   for(j=0;j<3;j++)
     {
     printf("%d\t",a[i][j]);
     }  
   printf("\n");
   }
getch();
}
How it Works ?
  1. For Every value of row Subscript , the column Subscript incremented from 0 to n-1 columns
  2. i.e For Zeroth row it will accept zeroth,first,second  column ( a[0][0],a[0][1],a[0][2]) elements
  3. In Next Iteration Row number will be incremented by 1 and the column number again initialized to 0 .
Accessing 2-D Array
a[i][j]  == Element From i-th Row and j-th Column

Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates