Skip to content

Commit

Permalink
Create WavePrintMatrixProgram.cpp
Browse files Browse the repository at this point in the history
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 : panditakshay402#222
  • Loading branch information
mreshank committed Oct 29, 2023
1 parent 15af29a commit 4d53aa6
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions C++/WavePrintMatrixProgram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//Wave Print Matrix Program - Mr. Eshank Tyagi
#include <iostream>
#include <vector>

int main()
{
std::vector<std::vector<int>> 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<int>(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;
}

0 comments on commit 4d53aa6

Please sign in to comment.