Advertisement
PROFESSOR_AIH

Square Matrix I

Apr 23rd, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,n,z,l,a,b;
  5.     while(1)
  6.     {
  7.         scanf("%d",&n);
  8.         if(n==0)
  9.             break;
  10.  
  11.         int arr[n][n];
  12.  
  13.         z=n/2;
  14.         if(n%2==1)
  15.             z++;
  16.         a=0;
  17.         b=n-1;
  18.         for(l=1; l<=z; l++)
  19.         {
  20.             for(i=a; i<=b; i++)
  21.             {
  22.                 for(j=a; j<=b; j++)
  23.                 {
  24.                     arr[i][j]=l;
  25.                 }
  26.             }
  27.             a++;
  28.             b--;
  29.         }
  30.  
  31.         for(i=0; i<n; i++)
  32.         {
  33.             for(j=0; j<n; j++)
  34.             {
  35.                 if(j==0)
  36.                 {
  37.                     printf("%3d",arr[i][j]);
  38.                 }
  39.                 else
  40.                     printf(" %3d",arr[i][j]);
  41.             }
  42.             printf("\n");
  43.         }
  44.         printf("\n");
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement