新人新帖 求教了啊? 程序编写
1 1 1 1 1 1 1 1 1 11 2 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 3 2 1
1 2 3 4 4 4 4 3 2 1
1 2 3 4 5 5 4 3 2 1
1 2 3 4 5 5 4 3 2 1
1 2 3 4 4 4 4 3 2 1
1 2 3 3 3 3 3 3 2 1
1 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 1
双循环for
#include <stdio.h> #define mymin(a,b) ((a)<=(b)?(a):(b)) int main() { const int n = 10; for( int i=0; i<n*n; ++i ) { int rmin = mymin( i/n+1, n-i/n ); int cmin = mymin( i%n+1, n-i%n ); int min = mymin( rmin, cmin ); printf( "%d%c", min, (i+1)%n==0?'\n':' ' ); } return 0; }