#include <iostream.h> #include <stdio.h> #define N 9 void main() {
int m,a[N][N]; char ch1,ch2; int i=0,j=0; int n=1,p=0;
L: do{ do{ cout<<"Input a number between 1-9"<<endl; cin>>m; if(m<1m>9) cout<<"Invalid!Again!"<<endl; }while(m<1m>9); while(n<=m*m) { while(j<m-p) { a[i][j]=n; j++;n++; } i++;j--; while(i<m-p) { a[i][j]=n; i++;n++; } i--;j--; while(j>=p) { a[i][j]=n; j--;n++; } i--;j++; while(i>p) { a[i][j]=n; i--;n++; } i++;j++; p++; }
cout<<"Result:"<<endl; for(i=0;i<m;i++) { for(j=0;j<m;j++) { printf("%4d",a[i][j]); } cout<<endl; } do{ cout<<"GO ON?(Y/N)"; cin>>ch1; if((ch1=='Y'ch1=='y')(ch1=='N'ch1=='n')) ; else cout<<"Illegal Char!Again!"<<endl; }while(!(ch1=='Y'ch1=='y'ch1=='N'ch1=='n')); }while(ch1=='Y'ch1=='y'); if(ch1=='N'ch1=='n') { cout<<"Really want to EXIT?(Y/N)"; cin>>ch2; if(ch2=='N'ch2=='n') goto L; } } |