-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmatrix.cpp
More file actions
99 lines (85 loc) · 1.71 KB
/
matrix.cpp
File metadata and controls
99 lines (85 loc) · 1.71 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
using namespace std;
void diagonal(int m,int n,int** arr)
{
int i,j;
for ( i = 0; i < m; i++)
{
for ( j = 0; j < n; j++)
{
if (i==j)
{
cout<<*(*(arr+i)+j)<<" ";
}
}
}
}
void Upper_triangle(int m,int n,int** arr)
{
int i,j,k;
for ( i = 0; i < m; i++)
{
for ( j = 0; j < n; j++)
{
if (i<=j)
{
cout<<*(*(arr+i)+j)<<" ";
}
}
}
}
void Lower_triangle(int m,int n,int** arr)
{
int i,j,k;
for ( i = 0; i < m; i++)
{
for ( j = 0; j < n; j++)
{
if (i>=j)
{
cout<<*(*(arr+i)+j)<<" ";
}
}
}
}
void enter(int m,int n,int** arr)
{
int i,j;
for ( i = 0; i < m; i++)
{
for ( j = 0; j < n; j++)
{
cin>>*(*(arr+i)+j);
}
}
}
void display(int m,int n,int** arr)
{
int i,j;
for ( i = 0; i < m; i++)
{
for ( j = 0; j < n; j++)
{
cout<<*(*(arr+i)+j)<<" ";
}
cout<<"\n";
}
}
int main()
{
int** arr=new int*[3];
int i,j;
for ( i = 0; i < 3; i++)
{
arr[i]=new int[3];
}
enter(3,3,arr);
cout<<"\nOriginal Matrix is: \n";
display(3,3,arr);
cout<<"\nDiagonals of the Matrix are: ";
diagonal(3,3,arr);
cout<<"\nUpper Triangular Matrix: ";
Upper_triangle(3,3,arr);
cout<<"\nLower Triangular Matrix: ";
Lower_triangle(3,3,arr);
}