Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*int main()
  6. {
  7. int a[30][30],n,i,j,m;
  8. cin>>n>>m;
  9. for(i=0;i<n;i++)
  10. for(j=1;j<=m;j++)
  11. a[0][i]=j;
  12. for(i=0;i<m;i++)
  13. for(j=1;j<=n;j++)
  14. a[i][0]=j;
  15. for(i=1;i<n-1;i++)
  16. for(j=1;j<m-1;j++)
  17. a[i][j]=a[i-1][j-1]++;
  18. for(i=0;i,n;i++)
  19. {for(j=0;j<m;j++)
  20. cout<<a[i][j]<<" ";
  21. cout<<endl;
  22. }
  23. }
  24. int main()
  25. {
  26. int a[30][30],n,i,j;
  27. cin>>n;
  28. for(j=0;j<n;j++)
  29. a[0][j]=j+1;
  30. for(i=1;i<n;i++)
  31. a[i][n-1]=n-i;
  32. for(i=1;i<n;i++)
  33. for(j=0;j<n-1;j++)
  34. a[i][j]=a[i-1][j+1];
  35. for(i=0;i<n;i++)
  36. {for(j=0;j<n;j++)
  37. cout<<a[i][j]<<" ";
  38. cout<<endl;
  39. }
  40.  
  41. }*/
  42. void citire(int &n)
  43. {
  44. cin>>n;
  45. }
  46. int main()
  47. {
  48. int a[50][50],n,i,K;
  49. citire(n);
  50. int s=0,t=n,j,x=1,l;
  51. if(n%2==0)
  52. l=n/2;
  53. if(n%2!=0)
  54. l=n/2+1;
  55. for(K=0;K<l;K++)
  56. {
  57. for(i=s;i<t;i++)
  58. {
  59. a[i][s]=x;
  60. a[i][t-1]=x;
  61. }
  62. for(j=s;j<t;j++)
  63. {
  64. a[s][j]=x;
  65. a[t-1][j]=x;
  66. }
  67. s++;
  68. t--;
  69. x++;
  70. }
  71. for(i=0;i<n;i++)
  72. {for(j=0;j<n;j++)
  73. cout<<a[i][j]<<" ";
  74. cout<<endl;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement