Explanation:-
2D-Array
is a collection of rows and columns and we also called as array of arrays.
Source code:-
Output:-
Source
code:-
For
create a matrix.
Output:-
Source
code:-
For displaying
matrix.
Code:-
For
Exiting the program:-
Executable Code :-
#include<iostream>
using
namespace std;
int
matrix[10][10],i,j,row,col;
void
create(int matrix[10][10],int row,int col);
void
display(int matrix[10][10],int row,int col);
int
main()
{
int ch,r,c,a[10][10];
do{
cout<<"Creating
Matrix and Displaying Matrix\n";
cout<<"1.Create
Matrix\n2.Display Matrix\n3.Exit\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter
the row for matrix:";
cin>>r;
cout<<"\nEnter
the column for matrix:";
cin>>c;
create(a,r,c);
break;
case 2:
display(a,r,c);
break;
case 3:
cout<<"\nExiting....";
exit(0);
break;
}
}while(ch!=3);
}
void
create(int matrix[10][10],int row,int col)
{
for(int i=1;i<=row;i++)
{
for(int j=1;j<=col;j++)
{
cout<<"Enter
the element at "<<i<<j<<" = ";
cin>>matrix[i][j];
}
}
}
void
display(int matrix[10][10],int row,int col)
{
for(int i=1;i<=row;i++)
{
for(int j=1;j<=col;j++)
{
cout<<matrix[i][j]<<"\t";
}
cout<<"\n";
}
}
Code Block with Line Numbers
|
|