#include<stdio.h> void main(){int array[19][19],dimension,first,second,count=1; printf("Please input the dimension: "); scanf("%d",&dimension); first=0; second=dimension/2; for(;count<=dimension*dimension;count++) {array[first][second]=count; if(count%dimension!=0) {first=(dimension+first-1)%dimension; second=(second+1)%dimension; } else if(count%dimension==0)first=first+1; } printf("\nThe array is:\n\n"); for(first=0;first<dimension;first++) {for(second=0;second<dimension;second++) {printf("%4d",array[first][second]); } printf("\n"); } printf("\nEnter Key To Exit......"); getch();}

评论