forked from bhawna-menghani/DSA_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSum_lowerTrianElement.cpp
More file actions
57 lines (55 loc) · 1.68 KB
/
Copy pathSum_lowerTrianElement.cpp
File metadata and controls
57 lines (55 loc) · 1.68 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
#include<iostream>
using namespace std;
int main()
{
int i, j, arr[10][10], sum, rows, cols;
cout<<"\n Enter Number of Rows : ";
cin>>rows;
cout<<"\n Enter Number of Columns : ";
cin>>cols;
for (i = 0; i < rows; i++) //Accepting the Elements in Matrix
{
for (j = 0; j < cols; j++)
{
cout<<"\n Enter the Elements : ";//<<arr[i]<<arr[j];
cin>>arr[i][j];
}
}
cout<<"\n Matrix is : \n";
for (i = 0; i < rows; i++) //Displaying the Elements in Matrix
{
cout<<" ";
for (j = 0; j < cols; j++)
{
cout<<" ";
cout<<arr[i][j];
}
cout<<"\n";
}
cout<<"\n Lower Triangle Elements : \n"; //Displaying Lower Triangular Elements
for (i = 0; i < rows; i++)
{
cout<<" ";
for (j = 0; j < cols; j++)
{
if (i > j)
{
cout<<" ";
cout<<arr[i][j];
}
}
cout<<"\n";
}
//Sum of all Lower Triangular Elements
sum = 0;
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
{
if (i > j)
{
sum = sum + arr[i][j];
}
}
cout<<"\n Sum of Lower Triangle Elements : "<<sum; //Printing the sum of lower triangular elements
return (0);
}