#include
void Print(int n){
int i,j;
int tmp=(n+1)/2;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
for(int k=1;k<=n;k++){
if(i==k || i==n-k+1 || j==k || j==n-k+1){
printf("%d ",tmp-k+1);
break;
}
}
}
printf("n");
}
}
int main(){
int n;
scanf("%d",&n);
Print(n);
return 0;
}参考这段代码哈,欢迎交流.满意请采纳.