forked from panditakshay402/Hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |