Type Here to Get Search Results !

C PROGRAM TO FIND WEATHER THE GIVEN MATRIX IS MAGIC SQUARE OR NOT

2

PROGRAM


CLICK THE COPY BUTTON BELOW TO COPY THE WHOLE PROGRAM        

YOU CAN ALSO COPY THE PROGRAM  FROM HERE

#include<stdio.h>

int main()

{

   int n,i,j,a[5[5],r1=0,r2=0,r3=0,c1=0,c2=0,c3=0,d1=0,d2=0;

  

   scanf("%d", &n);

   for(i=0; i<n; i++)

   {

       for(j=0; j<n; j++)

       {

           scanf("%d",&a[i][j]);

       }

   }

   for(i=0; i<n; i++)

   {

       r1=r1+a[0][i];

        r2=r2+a[1][i];

         r3=r3+a[2][i];

         c1=c1+a[i][0];

         c2=c2+a[i][1];

         c3=c3+a[i][2];

          d1=d1+a[i][i];


   }


      for(i=0,j=n-1; i<n&&j>=0; i++,j--)

   {

       d2=d2+a[i][j];   

   } 

   if(r1==r2&&r2==r3&&r3==c1&&c1==c2&&c2==c3&&c3==d1&&d1==d2)

   {

       printf("yes");

   }

   else

   {

       printf("no");

   }


}


In this code 

r1=sum of first row

r2=sum of second row

r3=sum of third row

c1=sum of first column

C2=sum of second column

c3=sum of third column



Post a Comment

2 Comments
  1. https://docs.google.com/spreadsheets/d/19y2KxTFHpU9UUW6OnqyLsUFYKIt-lQNoPZjxS9XE3qs/edit#gid=1654118553

    ReplyDelete
  2. https://github.com/darpan-jain/neetcode-solutions

    ReplyDelete
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad