-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2DArray.cpp
More file actions
127 lines (102 loc) · 2.36 KB
/
2DArray.cpp
File metadata and controls
127 lines (102 loc) · 2.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include<iostream>
#include<climits>
using namespace std;
void printcol(int arr[][4], int row, int col)
{
// column wise
for(int j=0; j<col; j++)
for(int i=0; i<row; i++)
cout<<arr[i][j]<<" ";
}
void printrowmax(int arr[][4], int row, int col)
{
int index = -1, sum = INT_MIN;
for(int i=0; i<row; i++)
{
int total = 0;
for(int j=0; j<col; j++)
total += arr[i][j];
if(total>sum)
{
sum = total;
index = i;
}
}
cout<<index<<" ";
}
void printsumdig(int matrix[][3], int row, int col)
{
int first = 0;
int sec = 0;
// first diagnoal sum
int i=0;
while(i<row)
{
first+=matrix[i][i];
i++;
}
// second diagnoal sum
i=0;
int j = col-1;
while(j>=0)
{
sec+=matrix[i][j];
i++,j--;
}
cout<<first<<" "<<sec<<" ";
}
void printrevercmat(int revers, int row, int col)
{
for(int i=0; i<row; i++)
{
int start=0, end=col-1;
while(start<end)
{
swap(revers[i][start], revers[i][end]);
start++, end--;
}
}
cout<<"Yes"<<" ";
}
int main()
{
// create 2D Array
int arr1[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int arr2[3][4] = {1,3,4,2,5,7,6,8,9,11,12,10};
int ans[3][4];
// Print all value in row wise
// for(int row=0; row<3; row++)
// for(int col=0; col<4; col++)
// cout<<arr[row][col]<<" ";
// Print all value in col wise function call
// printcol(arr,3,4);
// Find an Element in our array
// int x = 7;
// for(int row=0; row<3; row++)
// for(int col=0; col<4; col++)
// {
// if(arr[row][col]==x)
// {
// cout<<"Yes ";
// return 0;
// }
// }
// cout<<"No ";
// Add 2 Matrix
// for(int row=0; row<3; row++)
// for(int col=0; col<4; col++)
// {
// ans[row][col] = arr1[row][col] + arr2[row][col];
// }
// for(int row=0; row<3; row++)
// for(int col=0; col<4; col++)
// cout<<ans[row][col]<<" ";
// Print row index maximum sum
// printrowmax(arr2,3,4);
// Print Diagnoal Sum
// int matrix[3][3] = {1,2,3,4,5,6,7,8,9};
// printsumdig(matrix,3,3);
// Print Reverse rowof matrix
int revers[3][4] = {1,2,3,4,5,6,7,8,9,3,6,5};
printrevercmat(revers,3,4);
}