-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2d_array.cpp
More file actions
33 lines (30 loc) · 814 Bytes
/
2d_array.cpp
File metadata and controls
33 lines (30 loc) · 814 Bytes
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
#include<iostream>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
int arr[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
int col_start = 0, col_end = n-1, row_start = 0, row_end = m-1;
while(col_start<=col_end && row_start<=row_end){
for(int col=col_start;col<=col_end;col++){
cout<<arr[row_start][col]<<" ";
}
row_start++;
for(int row=row_start;row<=row_end;row++)
cout<<arr[row][col_end]<<" ";
col_end--;
for(int col=col_end;col>=col_start;col--)
cout<<arr[row_end][col]<<" ";
row_end--;
for(int row=row_end;row>=row_start;row--){
cout<<arr[row][col_start]<<" ";
}
col_start++;
}
return 0;
}