Advertisement
KAR98S

squareMatrix_to_spiral_sequence.c

Jan 14th, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #define p printf
  3. i,j,a[99][99],n,t,di=1,dj=1,f,l;
  4. int main() {
  5.     p("Enter n of a square matrix:");scanf("%d",&n);t=(l=n);p("\n");
  6.     for(i=j=0;i<n;a[i][j]=i*n+j+1,(++j-n)?0:(j=0,i++));
  7.     for(i=j=0;i<n;(++j-n)?0:(j=0,i++,p("\n")))p("%d\t",a[i][j]);
  8.     p("\nsequence: ");
  9.     for(i=j=0;l;p("%d,",a[i][j]),--t?0:(di*=1-2*f,dj*=2*f-1,t=l-=f=!f),i+=di*f,j+=dj*!f);
  10.     return 0;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement