.
Home About-us Privacy Policy Contact-us Services

Wednesday, October 7, 2015

C++ program to traverse a two dimensional array

ad+1


Program - 
 
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],n,m,i,j;
clrscr();
cout<<"\n enter the number of row and columns of a matrix:";
cin>>n>>m;
cout<<"\n enter array elements:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n entered matrix is:\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
}
getche();
}

Output - 



 enter the number of row and columns of a matrix:4 4

 enter array elements:3 4 5 6 4 5 6 7 8 3 4 5 6 7 8 9

 entered matrix is:

        3       4       5       6
        4       5       6       7
        8       3       4       5
        6       7       8       9

This is working on row and column. because matrix is combination of row and column.

0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates