اگه سوال رو درست فهمیده باشم این میشه ، این برای ماتریس 5*5
#include <iostream>
using namespace std ;
int main()
{
int a[5][5] ;
int cntr1 = 0 ,cntr2 = 0 , cntr3 = 0 ;
cout << "enter matrix (5*5) : " ;
for ( int i = 0 ; i < 5 ; i++ )
{
for ( int j = 0 ; j < 5 ; j++ )
{
cin >> a[i][j] ;
if ( a[i][j] == 0 )
++cntr3 ;
}
}
int n = a[0][0] ;
for ( int i = 0 ; i < 5 ; i++ )
{
if ( a[i][i] == 1 )
{
++cntr1 ;
}
}
for ( int i = 0 ; i < 5 ; i++ )
{
if ( a[i][ 4 - i ] == 1 )
{
++cntr2 ;
}
}
if ( (cntr1 == 5 || cntr2 == 5) && cntr3 == 20 )
cout << "1" << endl ;
else
cout << "-1" << endl ;
}