Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int N=100;
- int ar[N][N];
- int main()
- {
- int n,number=0,x=0,y=0;
- cin>>n;
- for(int gr=0; gr<(n+1)/2; gr++){
- ar[gr][gr]=number++;
- for(int j=gr; j+1<n-gr; j++){
- ar[gr][j+1]=ar[gr][j]+1;
- }
- for(int j=gr; j+1<n-gr; j++){
- ar[j+1][n-1-gr]=ar[j][n-1-gr]+1;
- }
- for(int j=n-1-gr; j>0+gr; j--){
- ar[n-1-gr][j-1]=ar[n-1-gr][j]+1;
- }
- for(int j=n-1-gr; j-1>gr; j--){
- ar[j-1][gr]=ar[j][gr]+1;
- number=ar[j-1][gr];
- }
- }
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- cout<<ar[i][j]<<' ';
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement