Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 9th, 2020 126 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.         i++;
  14.     }
  15.  
  16.     for (j=k;j<N-k+1;j++)
  17.     {
  18.         A[j][M-k]=p++;
  19.         i++;
  20.     }
  21.  
  22.     for (j=M-k-1;j>=k-1;j--)
  23.     {
  24.         A[N-k][j]=p++;
  25.         i++;
  26.     }
  27.  
  28.     for (j=N-k-1;j>=k;j--)
  29.     {
  30.         A[j][k-1]=p++;
  31.         i++;
  32.     }
  33.  
  34.  }
  35.   for (i=0; i<N; i++)
  36.   {
  37.     for (j=0; j<M; j++)
  38.     {
  39.       cout<<A[i][j]<<" ";
  40.     }
  41.     cout<<endl;
  42.   }
  43. }
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