Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 9th, 2020 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int N, M, A[N][M], i=0, j, k = 0, p=1;
  6. cin>>N>>M;
  7. while (i < N*M)
  8.  {
  9.     k++;
  10.     for (j=k-1;j<M-k+1;j++)
  11.     {
  12.         A[k-1][j]=p;
  13.         p++;
  14.         i++;
  15.     }
  16.  
  17.     for (j=k;j<N-k+1;j++)
  18.     {
  19.         A[j][M-k]=p;
  20.         p++;
  21.         i++;
  22.     }
  23.  
  24.     for (j=M-k-1;j>=k-1;j--)
  25.     {
  26.         A[N-k][j]=p;
  27.         p++;
  28.         i++;
  29.     }
  30.  
  31.     for (j=N-k-1;j>=k;j--)
  32.     {
  33.         A[j][k-1]=p;
  34.         p++;
  35.         i++;
  36.     }
  37.  
  38.  }
  39.   for (i=0; i<N; i++)
  40.   {
  41.     for (j=0; j<M; j++)
  42.     {
  43.       cout<<A[i][j]<<" ";
  44.     }
  45.     cout<<endl;
  46.   }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top