Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- int i,n,m,l,k,s,r;
- int a[100][100];
- int main ( )
- {
- ifstream read_file("input.txt");
- ofstream write_file("output.txt");
- cin>>n;
- r=0;
- while (k!=n*n)
- {
- r++;
- for(i=r;i<n-r+1;i++)
- {
- k++;
- a[r][i]=k;
- cout<<k<<endl;
- }
- for(i=r+1;i<n-r+1;i++)
- {
- k++;
- a[i][n-r+1]=k;
- cout<<k<<endl;
- }
- for(i=n-r;i>r;i--)
- {
- k++;
- a[n-s+1][i]=k;
- cout<<k<<endl;
- }
- for(i=n-r;i>r+1;i--)
- {
- k++;
- a[i][r]=k;
- cout<<k<<endl;
- }
- }
- for(i=0;i<n;i++)
- {
- for(m=0;m<n;m++)
- {
- cout<<" "<<a[i][m];
- }
- cout<<""<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement