title: Diagonal matrix in opposite direction in C
body: <p>I have a C code to produce diagonal identity matrix. The code is as follows:</p>
  <pre><code>#include&lt;stdio.h&gt;
      
  void main()
  {
      int n,m,a,b,c,d,i,j;
      int ar1[100][100];
        
      printf(&quot;Enter value of n to create a square matrix of order n (odd no.): &quot;);
      scanf(&quot;%d&quot;, &amp;n);
  
      printf(&quot; matrix in diagonal direction is - \n&quot;);
      for (i=0; i&lt;n; i++) {
          for (j=0; j&lt;n; j++) {
              if (ar1[j]==ar1[i]) {
                  ar1[j][i] = 2;
                  printf(&quot;%d, &quot;, ar1[j][i]);
              } else {
                  ar1[j][i] = -1;
                  printf(&quot;%d, &quot;, ar1[j][i]);
              }
          }
          printf(&quot;\n&quot;);
      }
  }
  </code></pre>
  <p>which gives me a result like this:</p>
  <pre><code> 2, -1, -1, -1, -1, 
  -1,  2, -1, -1, -1, 
  -1, -1,  2, -1, -1, 
  -1, -1, -1,  2, -1, 
  -1, -1, -1, -1,  2
  </code></pre>
  <p>but I want to print diagonal matrix in opposite direction like this:</p>
  <pre><code>-1, -1, -1, -1,  2, 
  -1, -1, -1,  2, -1, 
  -1, -1,  2, -1, -1, 
  -1,  2, -1, -1, -1, 
   2, -1, -1, -1, -1
  </code></pre>
  <p>Can somebody help me out, as to how to print diagonal matrix in opposite direction? I want to change the actual matrix not only the output</p>
  <hr />
  <p>I have updated my code like this (shown below) but still I am getting error (shown below)</p>
  <pre><code>#include&lt;stdio.h&gt;
      
  void main()
  {
       int n,m,a,b,c,d,i,j,s;
           int ar1[100][100];
        
       printf(&quot;Enter value of n to create a square matrix of order n (odd no.): &quot;);
       scanf(&quot;%d&quot;,&amp;n);
  
           printf(&quot;Enter m: (odd no.) &quot;);
       scanf(&quot;%d&quot;,&amp;m );
        
       
           if(n&gt;m)
            { 
       for(i=0;i&lt;n;i++)
       {
             for(j=0;j&lt;n;j++)
             {
                
                         for(a=1;a&lt;=(m-1)/2;a++){
                         if(ar1[i-a]==ar1[j]){
                         ar1[i][j] = 2;
                         printf(&quot;%d, &quot;,ar1[i][j]);
                        }
                        }
  
                        for(a=(m+1)/2;a&lt;=(n-1);a++){
                         if(ar1[i-a]==ar1[j]){
                         ar1[i][j] = -1;
                         printf(&quot;%d, &quot;,ar1[i][j]);
                        }
                        }
  
                        if(ar1[i]==ar1[j]){
                         ar1[i][j] = 2;
                         printf(&quot;%d, &quot;,ar1[i][j]);
                        }
  
                       for(a=1;a&lt;=(m-1)/2;a++){
                         if(ar1[i+a]==ar1[j]){
                         ar1[i][j] = 2;
                         printf(&quot;%d, &quot;,ar1[i][j]);
  
                        }
                        }
  
          for(a=(m+1)/2;a&lt;=(n-1);a++){
                         if(ar1[i+a]==ar1[j]){
                         ar1[i][j] = -1;
                         printf(&quot;%d, &quot;,ar1[i][j]);
                        }
                        }
  s = flip (ar1[100][100], n);
  
               }
             printf(&quot;\n&quot;);
       }
  
  void flip(int a[100][100], int n) {
   int t;
   for (i=0; i&lt;n; i++) {
       for (j=0; j&lt;n/2; j++) {
           t=a[i][j];
           a[i][j] = a[i][n-1-j];
           a[i][n-1-j] = t;
         }
     }
    }
      }
               
  }
  </code></pre>
  <p>and am getting errors like this</p>
  <pre><code>      /tmp/cc72v9hd.o: In function `main':
       faltu2.c:(.text+0x629): undefined reference to `flip'
       collect2: ld returned 1 exit status
  
  
  
      
  
  
  
         
  </code></pre>