#include<iostream>
using namespace std;
#define ROW 5
#define COL 5
void Show_Array(int ar[ROW][COL])
{for(int i=0;i<ROW;++i)
{
for(int j=0;j<COL;++j)
{
cout<<ar[i][j]<<" ";
}
cout<<endl;
}
}
void Show_Snake(int ar[ROW][COL])
{
bool right = true;
for(int i=0;i<ROW;++i)
{
if(right)
{
for(int j=0;j<COL;++j)
{
cout<<ar[i][j]<<" ";
}
cout<<endl;
right=false;
}
else
{
for(int j=COL-1;j>=0;--j)
{
cout<<ar[i][j]<<" ";
}
cout<<endl;
right=true;
}
}
}
void main()
{
int ar[ROW][COL];
for(int i=0;i<ROW;++i)
{
for(int j=0;j<COL;++j)
{
ar[i][j]=i+j;
}
}
Show_Array(ar);
cout<<"------------"<<endl;
Show_Snake(ar);
}
二维数组的“蛇形打印”输出
最新推荐文章于 2025-04-06 19:05:50 发布