#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],sum,p,q,r=0;
int i,j,x,n;
printf("\t Enter the no. of row in Matrix ");
scanf("%d",&x);
printf("\n\t Enter the no. of column in Matrix ");
scanf("%d",&n);
printf("\n\t Enter the Matrix of A : ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\tThe Matrix is : \n");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
printf(" %d",a[i][j]);
}
printf("\n");
}
sum=0;
for(i=0;i<x;i++){
for(j=0;j<n;j++) {
if(i == j)
{
sum=sum+a[i][j];
}
}
}
for(i=0;i<x;i++){
p=0;
for(j=0;j<n;j++) {
p=p+a[i][j];
}
if(sum == p)
r=1;
else
{
r=0;
break;
}
}
for(i=0;i<x;i++){
q=0;
for(j=0;j<n;j++) {
q=q+a[j][i];
}
if(sum == q)
r=1;
else
{
r=0;
break;
}
}
if(r==1)
{
printf("\n\tMatrix is Magic Square ");
}
else
{
printf("\n\t Matrix is not Magic Square ");
}
getch();
}
No comments:
Post a Comment
Please write your doubts