Two Dimensional Array

 In this data will be stored in form of rows and colums i.e. table.

A list of items can be given one variable name using two subscripts and such a variable is called a two -subscripted variable or a two -dimensional array.

Declaration syntax:-

Data_type  array_name[nr][nc];

nr->no.of rows

nc->no.of columns 

Initialization:-

int mat[2][3]=【{2,3,4}{5,6,7}】

i=0,j=0

1row,1col-->mat[0][0]=2;

1row,2col-->mat[0][1]=3;

1row,3col-->mat[0][2]=4;

.

.

.

2row,3col-->mat[1][2]=7;

In above example 

int is data type 

Mat is array name

2 is  total no.of rows

3 is total no.of columns

2,3,4,5,6,7 is elements

Program on two dimensional array

(Addition of two matrix)

#include <iostream.h>
#include <conio.h>
class arr
{
int a[10][10],b[10][10],i, j,nr,nc;
  public:
void acc();
void add();
};
void arr::acc()
{
cout<<"enter no of roos and colomus \n";
cin>>nr>>nc;
cout << "enter array values of a\n";
for (i = 0; i < nr; i++)
{
for (j = 0; j < nc; j++)
cin >> a[i][j];
}
cout << "enter Array values of b\n";
for (i = 0; i < nr; i++)
{
for (j = 0; j < nc; j++)
cin >> b[i][j];
}
}
void arr::add()
{
cout<<"\naddition of matrix\n";
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
cout<<(a[i][j]+b[i][j])<<"\t";
cout<<endl;
}
}
void main()
{
arr a;
clrscr();
a.acc();
a.add();
getch();
}
Out Put:-

Comments

Popular posts from this blog

History of C language

Lab programs of C

Algorithm Pseudopods Flow-chat