level 1
彳亍刈艹人
楼主
#include
#include
int findrow(int n,int row){ if (row >= 2) return row-1; else if (row == 1) return n;}int findcol(int n,int col){ if (col <= n-1) return col+1; else if (col == n) return 1; }main(){ int n,sqrt[16][16]={0},element=1; int col,row,i,j; printf("enter n(n=1 to 15):"); scanf("%d",&n); row = 1; col = n/2+1; sqrt[row][col]=1; for (element=2;element<=n*n;element++) { if (sqrt[findrow(n,row)][findcol(n,col)] == 0) { row = findrow(n,row); col = findcol(n,col); sqrt[row][col] = element; } else if (sqrt[findrow(n,row)][findcol(n,col)] != 0) { row++; sqrt[row][col] = element; } } printf("\n"); for (i=1;i<=n;i++) { for(j=1;j<=n;j++) if(sqrt[i][j]!=0) printf("%d\t",sqrt[i][j]); printf("\n"); } system("pause"); return 0; }
2008年12月15日 09点12分
1
#include
int findrow(int n,int row){ if (row >= 2) return row-1; else if (row == 1) return n;}int findcol(int n,int col){ if (col <= n-1) return col+1; else if (col == n) return 1; }main(){ int n,sqrt[16][16]={0},element=1; int col,row,i,j; printf("enter n(n=1 to 15):"); scanf("%d",&n); row = 1; col = n/2+1; sqrt[row][col]=1; for (element=2;element<=n*n;element++) { if (sqrt[findrow(n,row)][findcol(n,col)] == 0) { row = findrow(n,row); col = findcol(n,col); sqrt[row][col] = element; } else if (sqrt[findrow(n,row)][findcol(n,col)] != 0) { row++; sqrt[row][col] = element; } } printf("\n"); for (i=1;i<=n;i++) { for(j=1;j<=n;j++) if(sqrt[i][j]!=0) printf("%d\t",sqrt[i][j]); printf("\n"); } system("pause"); return 0; }