title: Diagonal Difference in c
body: <p>Consider the following code. I have to find the difference of both diagonals in C.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
  
      int n,a[100][100],sum1=0,sum2=0;
      scanf("%d",&amp;n);
      for(int i=0;i&lt;n;++i)
          {
          for(int j=0;j&lt;n;++j){
  
              scanf("%d",&amp;a[i][j]);
               if(i==j) sum1+=a[i][j];
               else if((i+j)==(n-1)) sum2+=a[i][j];
  
          }
      }
       if(sum1&gt;sum2) printf("%d",(sum1-sum2));
       else printf("%d",(sum2-sum1));
  
  
      return 0;
  }
  </code></pre>
  
  <p>When I change <code>else if</code> to <code>if</code>, then the code works fine. Why?</p>