http://blog.csdn.net/xiaofei2010/article/details/7982456
#include <iostream> using namespace std; int main() { int a[10][10],count = 1; for (int k = 0,n = 10;k < n;n--,k++)// {//k表示第一行,n表示最后一行。4个FOR循环后,减两行,因此n--,k++ for (int i = k;i < n;i++) a[k][i] = count++; for (int i = k + 1;i < n;i++) a[i][n-1] = count++; for(int i = n - 2;i >= k;i--) a[n-1][i] = count++; for(int i = n - 2;i > k;i--) a[i][k] = count++; } for (int i = 0;i < 10;i++) { for (int j = 0;j < 10;j++) cout << a[i][j] << " " ; cout << endl; } return 0; }
时间: 2024-12-29 06:58:42