请问这题该怎么做
输入可大可小的正方形图案,最外层是第一层,要求每层上用的数字与层数相同。Input n: 3
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
#include <stdio.h> #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) ) void fun( unsigned n ) { for( unsigned i=0; i!=(2*n-1)*(2*n-1); ++i ) { unsigned r = i/(2*n-1); unsigned c = i%(2*n-1); unsigned v = MIN( MIN(r+1,2*n-1-r), MIN(c+1,2*n-1-c) ); printf( "%d%c", v, " \n"[(i+1)%(2*n-1)==0] ); } } int main( void ) { fun( 3 ); return 0; }