From 4d53aa63bde19e2d9a623705daa1b32ea312cebc Mon Sep 17 00:00:00 2001 From: Eshank Tyagi <111590631+mreshank@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:48:32 +0530 Subject: [PATCH] Create WavePrintMatrixProgram.cpp This is the program for the "Wave Print Matrix Program" addressed in the Issue Number 222. I believe this is exactly what was asked to do, so kindly merge it into the repo. This is the C++ Version of the same, i have also requested for the Java version too in my previous PR, so kindly see that too if it haven't been merged yet. Link to the issue : https://github.com/panditakshay402/Hacktoberfest2023/issues/222 --- C++/WavePrintMatrixProgram.cpp | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 C++/WavePrintMatrixProgram.cpp diff --git a/C++/WavePrintMatrixProgram.cpp b/C++/WavePrintMatrixProgram.cpp new file mode 100644 index 0000000..c10c8d6 --- /dev/null +++ b/C++/WavePrintMatrixProgram.cpp @@ -0,0 +1,59 @@ +//Wave Print Matrix Program - Mr. Eshank Tyagi +#include +#include + +int main() +{ + std::vector> arr; + int r, c; + + std::cout << "\nEnter the number of rows : "; + std::cin >> r; + + std::cout << "\nEnter the number of columns : "; + std::cin >> c; + + arr.resize(r, std::vector(c)); + + std::cout << "\nEnter the elements of the matrix :-\n"; + + for(int i = 0; i < r; i++) + { + for(int j = 0; j < c; j++) + { + std::cin >> arr[i][j]; + } + } + + std::cout << "The matrix is :-\n"; + + for(int i = 0; i < r; i++) + { + for(int j = 0; j < c; j++) + { + std::cout << arr[i][j] << " "; + } + std::cout << std::endl; + } + + std::cout << "The wave print of the matrix is :-\n"; + + for(int i = 0; i < c; i++) + { + if(i % 2 == 0) { + for(int j = 0; j < r; j++) + { + std::cout << arr[j][i] << " "; + } + } + else + { + for(int j = r - 1; j >= 0; j--) + { + std::cout << arr[j][i] << " "; + } + } + } + + return 0; +}