Write a program to check whether given matrix is magic square matrix or not .
#include<iostream>
using namespace std;
int main()
{
int size=3;
int matrix[3][3]; //(4,9,2),(3,5,7),(8,1,6);
int row,column=0;
int sum,sum1,sum2;
int flag=0;
cout<<"\n enter the matrix: ";
for(row=0; row<size; row++)
{
for(column=0; column<size; column++)
cin>>matrix[row][column] ;
}
cout<<"entered matrix is : ";
for(row=0; row<size; row++)
{
cout<<" \n ";
for(column=0; column<size; column++)
{
cout<<matrix[row][column] ;
}
}
// for diagonal elements
sum=0;
for(row=0; row<size; row++)
{
for(column=0; column<size; column++)
{
if(row == column)
sum= sum+ matrix[row][column];
}
}
//for rows
for(row=0; row<size; row++)
{
sum1=0;
for(column=0; column<size; column++)
{
sum1=sum1 + matrix[row][column];
}
if(sum == sum1)
flag=1;
else
{
flag=0;
break;
}
}
// for columns
for(row=0; row<size; row++)
{
sum2=0;
for(column=0; column<size; column++)
{
sum2=sum2 + matrix[column][row];
}
if(sum == sum2)
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
cout<<"\n magic square: ";
else
cout<<"\n no magic square";
}