-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreOfMatrix.cpp
115 lines (115 loc) · 3.04 KB
/
MoreOfMatrix.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream>
using namespace std;
int main()
{
int m[10][10];
int i,j,n,k,sumd1=0,sumd2=0,suml=0,sumu=0;
cout<<"Enter the order of the matrix: ";
cin>>n;
cout<<"\nEnter the elements: "<<endl;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin>>m[i][j];
}
}
cout<<"\nThe matrix is: ";
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cout<<m[i][j]<<" ";
}
cout<<"\n";
}
do
{
cout<<"\nEnter a choice:\n\n1. Modify the Matrix\n2. Sum of Leading Diagonal Elements \n3. Sum of Second Diagonal Elements \n4. Sum of Upper Triangle Elements\n5. Sum of Lower Triangle Elements\n0. Exit\n\n";
cin>>k;
switch(k)
{
case 1:
{
cout<<"Enter the order of the matrix: ";
cin>>n;
cout<<"\nEnter the elements: "<<endl;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin>>m[i][j];
}
}
cout<<"\nThe matrix is: \n";
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cout<<m[i][j]<<" ";
}
cout<<"\n";
}
break;
}
case 2:
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i==j)
sumd1+=m[i][j];
}
}
cout<<"\nSum of Leading Diagonal Elements is: "<<sumd1<<endl;
break;
}
case 3:
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i+j==n-1)
sumd2+=m[i][j];
}
}
cout<<"\nSum of Second Diagonal Elements is: "<<sumd2<<endl;
break;
}
case 4:
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i>j)
sumu+=m[i][j];
}
}
cout<<"\nSum of Upper Triangle Elements is: "<<sumu<<endl;
break;
}
case 5:
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i<j)
suml+=m[i][j];
}
}
cout<<"\nSum of Lower Triangle Elements is: "<<suml<<endl;
break;
}
case 0:
cout<<"Bye! Have a great time"<<endl;
break;
default:
cout<<"Invalid input!";
}
}while(k!=0);
return 0;
}