在这个问题上,我们得到一个二维矩阵。我们的任务是打印矩阵的锯齿形。
让我们以一个例子来了解问题Input:
12 99 43
10 82 50
15 75 5
Output: 12 99 43 50 82 10 15 75 5
为了解决这个问题,我们将在两个方向(LtoR和RtoL)上打印数组的元素。并使用flag变量更改方向。
示例#include
using namespace std;
void printZigZagPattern(int row, int col, int a[][5]) {
int evenRow = 0;
int oddRow = 1;
while (evenRow
for (int i=0;i
cout<
}
evenRow = evenRow + 2;
if(oddRow
for (int i=col-1; i>=0; i--)
cout<