-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2D_array.cpp
More file actions
56 lines (56 loc) · 1.12 KB
/
Copy path2D_array.cpp
File metadata and controls
56 lines (56 loc) · 1.12 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
#include <iostream>
using namespace std;
int main()
{
int arr[3][3],i,j;
cout<<"Enter the elements of 2d array"<<endl;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{cin>>arr[i][j];}}
//row measure array
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{cout<<arr[i][j]<<"\t";}
cout<<endl;}
cout<<endl;
//column measure array or transpose
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{cout<<arr[j][i]<<"\t";}
cout<<endl;}
cout<<endl;
//sum of rows and columns and largest sum
int x,y;
for(i=0;i<3;i++)
{int sum=0,sum1=0,row,column;
for(j=0;j<3;j++)
{
sum+=arr[i][j];
sum1+=arr[j][i];
}
cout<<"The sum of "<<i+1<<" row is "<<sum<<endl;
cout<<"The sum of "<<i+1<<" column is "<<sum1<<endl;
if(row<sum)
{row=sum;
y=i;}
if(column<sum1)
{column=sum1;
x=i;}}
cout<<"The "<<y<<" row has largest sum "<<endl;
cout<<"The "<<x<<" row has largest column "<<endl;
//diagonal sum
int sumd1=0,sumd2=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j){
sumd1+=arr[i][j];}
if(i+j==2){
sumd2+=arr[i][j]; }
}
}
cout<<"The sum of primary diagonals is "<<sumd1<<endl;
cout<<"The sum of secondary diagonals is "<<sumd2<<endl;
return 0;
}