1 蛇形矩阵
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a[105][105];
int main()
{
int n;
cin >> n;
int x = 1, y = 1;
int pos = 1;
int f = 1;
while (f!=n+1)
{
a[x][y] = pos;
pos++;
if (j == f){
f++;
x = f;
y = 1;
}
else{
x--;
y++;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (a[i][j] > 0)
cout << a[i][j]<<" ";
}
cout << '\n';
}
return 0;
}
**2 **
原博客