-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransposeMat.cpp
More file actions
52 lines (46 loc) · 1.02 KB
/
transposeMat.cpp
File metadata and controls
52 lines (46 loc) · 1.02 KB
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>
int **createMat(int, int);
void inputMat(int**, int, int);
void transpose(int**, int, int);
void delMat(int**, int);
int main()
{
int **arr = NULL, rows, columns = 0;
std::cout << "Enter the number of rows and columns" << std::endl;
std::cin >> rows >> columns;
arr = createMat(rows, columns);
std::cout << "Enter the number of elements in the matrix" << std::endl;
inputMat(arr, rows, columns);
transpose(arr, rows, columns);
delMat(arr, rows);
}
int **createMat(int row, int col)
{
int **arrp = new int*[row];
for(int i = 0; i < row; i++)
*(arrp + i) = new int[col];
return arrp;
}
void inputMat(int **arr, int row, int col)
{
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
std::cin >> *(*(arr + i) + j);
}
}
void transpose(int **arr, int row, int col)
{
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
std::cout << arr[j][i] << " ";
std::cout << "\n";
}
}
void delMat(int **arr, int row)
{
for(int i = 0; i < row; i++)
delete [] arr[i];
delete [] arr;
}