To understand how to read matrix of size m x n using function, you need to understand the concept of functions.
C++ program to read matrix of size m x n using function
/*C++ program to read matrix of size m x n using function*/
#include<iostream>
using namespace std;
void getarray(int a[10][10],int x,int y);
int main()
{
int a[10][10],m,n,i,j;
cout<<"Enter the value of m and n : ";
cin>>m>>n;
getarray(a,m,n);
cout<<endl;
cout<<"You have entered following matrix"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}
void getarray(int a[10][10],int x,int y)
{
int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cin>>a[i][j];
}
}
}
OUTPUT:
Enter the value of m and n : 3 3
1
2
3
1
2
3
1
2
3
You have entered following matrix
1 2 3
1 2 3
1 2 3
cin>>a[i][j]..here cin is not declared
ReplyDelete