Two- Dimensional Arrays

TWO DIMENSIONAL ARRAYS in C


Two dimensional arrays are used to arrange data in tabular form. In these arrays we have rows and columns. It is basically a two dimensional matrix with specific number of rows and columns.


For Example: -
int a[4][3];
 

This represents a two-dimensional array of integer type with 4 rows and 3 columns.
Each element is referred by its row and column number.
 

For Example:-

a[0][0],a[1][0],a[3][0],a[0][1],a[3][2] etc.
 

Where ,

a[i][j] represents elements of array.

  • Two dimensional arrays find a wide range of applications in maintaining records.

 

For Example:-


•    Marks obtained by different students in different subjects.
•    No of different items sold by number of salesgirl.
 

SYNTAX

Data type  array_name[row_size][column_size];
 

For Example:- a[0][0],a[1][0],...a[3][0],a[0][1],........a[i-1][j-1]

Where ‘i’ represents row size and ‘j’ represents column size.
 

ARRAY DECLARATION


•    int  marks[][3]={
           {2 1,6}    
           {3,5,9}
         };

  • Note:-It is necessary to specify size of column in array declaration but row can be left empty.


•    Char array[3][2];

  • Values in the elements of array can be assigned at the run time or by assignment operator in program itself as we did in case of One- Dimensional array.


Example: - To add two matrix of dimensions 2X3, with one matrix having defined values and one given at run time.
 

#include<stdio.h>
#include<conio.h>

int main()
{
int i=0,j=0,k=0;
int a[2][3]={2,3,6,1,0,8};
int b[2][3]={0}, sum[2][3]={0};
clrscr();
printf(" Enter the elements of matrix 'b'\n");
for(i=0;i<2;i++)
    for(j=0;j<3;j++)

      
 {
        printf(" Element No. %d-",k+1);
        scanf("%d",&b[i][j]);
        k++;
        }

for(i=0;i<2;i++)
    for(j=0;j<3;j++)
    {
     sum[i][j]=(a[i][j]+b[i][j]);
    }

for(i=0;i<2;i++)
    for(j=0;j<3;j++)

      
 {
        printf("%d, ",sum[i][j]);
        }

getch();
}

 

EXPLANANTION
 

This example finds the sum of two 2X3 matrix, in which matrix ‘a’ has values fed into the source code itself and values in ‘b’ is taken from standard input device during run time.
Finaly sum is found out and printed on the standard output device, in my case it is monitor.


OUTPUT

Enter the elements of matrix ‘b’
Element No. 1-3
Element No. 2-2
Element No. 3-5
Element No. 4-6
Element No. 5-7
Element No. 6-9

Sum of matrix ‘a’ and ‘b’: -
5, 5, 11, 7, 7, 17


 

Comments

Member since:
7 August 2017
Last activity:
1 year 7 weeks

kanye west shoes

michael kors bags

ua shoes

ray ban erika

prada handbags

payless shoes online

official kate spade website

coach outlet online

pandora rings

pandoracharms

pandora rings uk

Coach Sunglasses Outlet

balenciaga outlet

Engagement Rings - Official

Nike Air Max 180

official michael kors

Ray Ban sunglasses

shoes sale

Nike Air Max

Air Max 180

burberry outlet

Dreamland Jewelry - Official

birkenstock sandals

birkenstock

Nike Air Max Couple

coach outlet online

prada outlet online

louis vuitton outlet online

Nike Air Jordan

gel kayano

official michael kors

michael kors outlet bags

Hugo Boss Store

payless shoes

Premier Jewelry - Official

ray ban outlet

Coach Handbags

pandora sale

coach watches

nike store

football jerseys

louis vuitton outlet online

coach outlet online sale

Add Your Link Free

backlink

louis vuitton us

michael kors

Nike Air Jordan Enfants

michael kors

Michael Kors Handbags Outlet Sale

kate spade outlet online

Green Cleaned

ugg boots

sunglasses

Nike Blazer Femmes

evbid

Wine

coach outlet

birkenstock outlet

Burberry Australia

payless near me

Chanel Outlet

north face sale

Nike Air Max

Prada Shoes - Official

michael kors outlet

ray ban wayfarer sunglasses

Oakley Sunglasses

puma sneakers outlet

payless shoes

nike free shoes

diesel watches

burberry outlet canada

prada sale

puma sneakers sale

louis vuitton outlet

Air Max 180 Homme

Jewelry Armoire - Official

coach handbags sale

Hermes Outlet

timberland shoes

Nike Air Max 2017

coachs outlet

louis vuitton outlet online

Nike Jordans

football jerseys

burberry outlet sale

Nike Free 3.0

michael kors outlet online

ray ban wayfarer

ray ban sunglasses

Rolex Watch

michael kors

michael kors

nike huarache shoes

ray ban sale

Adamson

pandora necklaces

kate spade italy

coach australia

pandora uk

pandora uk

swatch watch

michael kors watches

michael kors

rayban prescription sunglasses

Brighton Jewelry - Official

prada outlet online

Nike Air Force

michael kors outlet

fulam shoes

softball jerseys

Nike Air Max

balenciaga us

Air Max 1 Homme

michael kors

Watches

Air Jordan Enfant

chrome store canada

sunglasses store

coach outlet

michael kors outlet

Nike Free Run

mk outlet online

michael kors outlet

the beat

seiko watches

michael kors

Lifestyle

Air Max 90 Femme

hermes outlet

Nike Air Jordan enfants

hermes outlet

prada purses

kate spade outlet

nike jordan shoes

me adc8.7