Advertisement
Guest User

jj

a guest
Mar 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int N=100;
  4. int ar[N][N];
  5. int main()
  6. {
  7. int n,number=0,x=0,y=0;
  8. cin>>n;
  9. for(int gr=0; gr<(n+1)/2; gr++){
  10. ar[gr][gr]=number++;
  11. for(int j=gr; j+1<n-gr; j++){
  12. ar[gr][j+1]=ar[gr][j]+1;
  13. }
  14. for(int j=gr; j+1<n-gr; j++){
  15. ar[j+1][n-1-gr]=ar[j][n-1-gr]+1;
  16. }
  17. for(int j=n-1-gr; j>0+gr; j--){
  18. ar[n-1-gr][j-1]=ar[n-1-gr][j]+1;
  19. }
  20. for(int j=n-1-gr; j-1>gr; j--){
  21. ar[j-1][gr]=ar[j][gr]+1;
  22. number=ar[j-1][gr];
  23. }
  24. }
  25. for(int i=0; i<n; i++){
  26. for(int j=0; j<n; j++){
  27. cout<<ar[i][j]<<' ';
  28. }
  29. cout<<endl;
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement