-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct.cpp
52 lines (42 loc) · 970 Bytes
/
struct.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
using namespace std;
int ** readmatrix( int m, int n);
void displaymatrix(int **k, int m, int n);
int main()
{
int **matrix;
int M,N;
cout<<"Enter the number of rows m = ";
cin>>M;
cout<<endl<<"Enter the number of columns n = ";
cin>>N;
matrix = readmatrix(M,N);
displaymatrix(matrix,M,N);
delete [][] matrix;
return 0;}
int ** readmatrix(int m, int n)
{
int **memalloc;
memalloc = new int[m][n];
if (memalloc != NULL)
{
for ( int i=0; i<m;i++)
{ for (int j=0;j<n;j++)
cin>>memalloc[i][j];
return (memalloc);
}
}
else
{
cout<<"Couldn't allocate memory"<<endl;
return NULL;
}
}
void displaymatrix(int **k, int m, int n)
{
for(int i=0; i<m; i++)
{ cout<<endl;
for(int j=0;j<n;j++)
cout<<k[i][j]<<" ";
} return;
}