-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA_23_2D_Array.cpp
More file actions
74 lines (73 loc) · 1.68 KB
/
DSA_23_2D_Array.cpp
File metadata and controls
74 lines (73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
bool ispresent(int arr[][3],int target,int row,int col){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(arr[i][j]==target){
return 1;
}
}
}
return 0;
}
void printrowsum(int arr[][3],int row,int col){
for(int i=0;i<row;i++){
int sum=0;
for(int j=0;j<col;j++){
sum+=arr[i][j];
}
cout<<"Sum 0f "<<i<<" Row is "<<sum<<endl;
}
}
void printcolsum(int arr[][3],int row,int col){
for(int i=0;i<col;i++){
int sum=0;
for(int j=0;j<row;j++){
sum+=arr[j][i];
}
cout<<"Sum 0f "<<i<<" Column is "<<sum<<endl;
}
}
void largestrowsum(int arr[][3],int row,int col){
int maxi=INT8_MIN;
int num=-1;
for(int i=0;i<row;i++){
int sum=0;
for(int j=0;j<col;j++){
sum+=arr[i][j];
}
if(sum>maxi)
{maxi=sum;
num=i;}
}
cout<<"Sum 0f "<<num<<" Row is largest which is "<<maxi<<endl;
}
int main(){
int arr[3][3];
cout<<"Namastey Duniya \n"<<endl;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cin>>arr[i][j];
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
// int target;
// cout<<"Enter the element to Searched: ";
// cin>>target;
// if(ispresent(arr,target,3,4)){
// cout<<"Found"<<endl;
// }
// else{
// cout<<"Not found"<<endl;
// }
printrowsum(arr,3,3);
// printcolsum(arr,3,3);
largestrowsum(arr,3,3);
cout<<"Namastey Duniya \n"<<endl;
return 0;
}