Check if sum of middle row & column is equal - C

C program to read 3*3 matrix and check sum of middle row is equal to sum of middle column.

Solution:

Following diagram shows the middle row and the middle column elements.

middle row element                      middle coloumn element

#include <stdio.h>
int main()
{
     int a[3][3],i,j,k,s1=0,s2=0;
     printf("Enter Elements for Matrix of Size 3*3:\n\n");
     /*Reads the numbers or elements for 3*3 matrix*/
     for(i=0;i<=2;i++)
          for(j=0;j<=2;j++)
          {
               scanf("%d",&a[i][j]);
          }
     /* For printing the elements in matrix form*/
     printf("\nMatrix is:\n\n");
     for(i=0;i<=2;i++)
     {
          for(j=0;j<=2;j++)
          {
               printf("%d ",a[i][j]);
          }
          printf("\n");
     }
     /* To print and sum of middle row elements*/
     printf("\nMiddle Row Elements: ");
     for(k=0;k<=2;k++)
     {
          s1=s1+a[1][k];
          printf("%d ",a[1][k]);
     }
     printf("\nSum of Middle Row Elements : %d\n",s1);
     /* To print and sum of middle column elements*/
     printf("\nMiddle Column Elements : ");
     for(k=0;k<=2;k++)
     {
          s2=s2+a[k][1];
          printf("%d ",a[k][1]);
     }
     printf("\nSum of Middle Column Elements : %d\n",s2);
     /* Check the of middle row EQUALS to middle column */
     if(s1==s2)
          printf("\nSum is EQUAL");
     else
          printf("\nSum is NOT EQUAL");
     return 0;
}


Output:

sum middle row column

Note - To find middle row and middle column of a matrix it should be a square matrix 3*3, 5*5, 7*7 etc.