#include<iostream> using namespace std; int main() { int i, j, k, num, a[100][100]; k = 1; //步数 i = 2;//横坐标 j = 2;//纵坐标 num = 0; for (k = 1; k <= 5; k++) { if (k % 2 == 1)//右上走 { int p = j; for (j; j < (p + k); j++) { a[i][j] = num; num++; } int q = i; for (i; i>(q - k); i--) { a[i][j] = num; num++; } } //else//左下 if (k % 2 == 0)//右上走 { int m = j; for (j; j > (m - k); j--) { a[i][j] = num; num++; } int n = i; for (i; i < (n + k); i++) { a[i][j] = num; num++; } } } for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { if (a[i][j] < 10) { cout << "0" << a[i][j] << " "; } else { cout << a[i][j] << " "; } } cout << endl; } return 0; }