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
https://docs.google.com/spreadsheets/d/19y2KxTFHpU9UUW6OnqyLsUFYKIt-lQNoPZjxS9XE3qs/edit#gid=1654118553
ReplyDeletehttps://github.com/darpan-jain/neetcode-solutions
ReplyDelete