题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <stdio.h> int main() { int a, b,c,f; scanf("%d",&a); c=1; while(c<=a&&c>=0) { for(b=1;b<=(a-c+1);b++) { if(b>0&&b!=(a-c+1)) //每行循环输出 printf("%d ",(((b+c-1)*(b+c-1)+(b+c-1))/2-c+1)); else if(b==(a-c+1)) //判断一行是输出结束 printf("%d\n",(((b+c-1)*(b+c-1)+(b+c-1))/2-c+1)); } c++; } return 0; }