3_11.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include <iostream.h>
- const int N=15;
- void main()
- {
- int i,j,k,m,n;
- int G[N][N];
- cout<<"Input the odd number you want!"<<endl;
- cin>>m;
- if ((m>0)&&(m%2))
- {
- cout<<"your inputed number is "<<m<<endl;
- n=m*m;
- j=0;
- k=m/2;
- for (i=1;i<=n;i++)
- {
- G[j][k]=i;
- if(i%m==0)
- if(j==m-1)
- j=0;
- else j++;
- else
- {
- if(j==0)
- j=m-1;
- else j--;
- if (k==m-1)
- k=0;
- else k++;
- }
- }
- for(i=0;i<m;i++)
- {
- for(j=0;j<m;j++)
- cout<<G[i][j]<<" ";
- cout<<endl;
- }
- }
- else cout<<"the number you inputed is error!"<<endl;
- }