Created
August 6, 2017 18:25
-
-
Save sujaykundu777/783c9ddc141f81f58fbff191480fa787 to your computer and use it in GitHub Desktop.
Passing 2d Matrix as a Function Parameter in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void getData(int mat[][10],int row, int col); | |
void display(int mat[][10],int row, int col); | |
int main() | |
{ | |
int row, col; | |
int mat[10][10]; | |
cout<<"Enter the dimensions of the matrix"; | |
cin>>row>>col; | |
//Get the input for the matrix | |
getData(mat,row,col); | |
//Display the matrix | |
display(mat,row,col); | |
return 0; | |
} | |
//Function to get the input of the dimensions from the user | |
//Its not required to input the i for the matrix as a parameter | |
void getData(int mat[][10],int row,int col){ | |
int i , j; | |
for(i=0;i<row;i++){ | |
for(j=0;j<col;j++){ | |
cout<<"Enter the elements of the matrix for :"<< i+1 << ":" << j+1 << ":"; | |
cin>>mat[i][j]; | |
} | |
} | |
} | |
void display(int mat[][10],int row,int col) | |
{ | |
int i,j; | |
cout<<"Output matrix : "<<endl; | |
for(i=0;i<row;i++){ | |
for(j=0;j<col;j++){ | |
cout<<mat[i][j]<<" "; | |
if(j == col-1) | |
cout << endl << endl; | |
cout<<endl; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment