From 7dc8777ae0a319805e1d568d9e7afc24ebcaf7a4 Mon Sep 17 00:00:00 2001 From: Amogh Jalan Date: Fri, 6 Mar 2020 16:57:59 +0530 Subject: [PATCH 1/2] Spiral Array C++ --- Spiral_Array/Spiral_Array.cpp | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Spiral_Array/Spiral_Array.cpp diff --git a/Spiral_Array/Spiral_Array.cpp b/Spiral_Array/Spiral_Array.cpp new file mode 100644 index 0000000000..c8b6bef3f1 --- /dev/null +++ b/Spiral_Array/Spiral_Array.cpp @@ -0,0 +1,83 @@ +//SPIRAL PRINTING 2-D matrix + +#include +using namespace std; + +int main() +{ + int m, n; + int left, right, top, bottom; + int i, j, count, dir; + int arr[100][100]; + + cin>>m>>n; // Matrix of m*n + + left = 0; + right = n-1; + top = 0; + bottom = m-1; + + count = m * n; //no. of elements + dir = 1; + + for (i=0; i>arr[i][j]; + } + + while (left <= right && top <= bottom && count > 0) + { + if (dir == 1) //left to right + { + for (i = left; i <= right; i++) + { + cout<= left; i--) + { + cout<= top; i--) + { + cout< Date: Mon, 9 Mar 2020 18:01:10 +0530 Subject: [PATCH 2/2] Changes Added --- Spiral_Array/Spiral_Array.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Spiral_Array/Spiral_Array.cpp b/Spiral_Array/Spiral_Array.cpp index c8b6bef3f1..787c864e80 100644 --- a/Spiral_Array/Spiral_Array.cpp +++ b/Spiral_Array/Spiral_Array.cpp @@ -1,4 +1,4 @@ -//SPIRAL PRINTING 2-D matrix +// SPIRAL PRINTING 2-D matrix #include using namespace std; @@ -10,29 +10,29 @@ int main() int i, j, count, dir; int arr[100][100]; - cin>>m>>n; // Matrix of m*n + cin >> m >> n; // Matrix of m*n left = 0; right = n-1; top = 0; bottom = m-1; - count = m * n; //no. of elements + count = m * n; // no. of elements dir = 1; - for (i=0; i>arr[i][j]; + for (j = 0; j < n; j++) + cin >> arr[i][j]; } while (left <= right && top <= bottom && count > 0) { - if (dir == 1) //left to right + if (dir == 1) // left to right { for (i = left; i <= right; i++) { - cout<= left; i--) { - cout<= top; i--) { - cout<