How would you write a function to check all rows, columns anddiagonals for all 1
ID: 3618926 • Letter: H
Question
How would you write a function to check all rows, columns anddiagonals for all 1's and if finds any change the value from all1's to all 2's. This is my function but it doesn't work.int check ( int a[][SIZE] )
{
int i, j;
for( i = 0; i < SIZE; i++ )
{
for( j = 0;j < SIZE; j++ )
{
if( a[i][0] == 1 || aa[i][1] == 1 || a[i][2] == 1 || a[i][3] == 1|| a[i][4] == 1 )
{
a[i][0] == 2;
a[i][1] == 2;
a[i][2] == 2;
a[i][3] == 2;
a[i][4] == 2;
return 1;
}
}
}
for( i = 0; i < SIZE; i++ )
{
for( j = 0;j < SIZE; j++ )
{
if( a[0][j] == 1 || a[1][j] == 1 || a[2][j] == 1 || a[3][j] == 1 ||a[4][j] == 1 )
{
a[0][j] == 2;
a[1][j] == 2;
a[2][j] == 2;
a[3][j] == 2;
a[4][j] == 2;
return 1;
}
}
}
if( a[0][0] == 1&& a[1][1] == 1 && a[2][2] == 1 && aa[3][3]== 1 && a[4][4] == 1 )
{
a[0][0] == 2;
a[1][1] == 2;
a[2][2] == 2;
a[3][3] == 2;
a[4][4] == 2;
return 1;
}
if( a[4][0] == 1&& a[3][1] == 1 && a[2][2] == 1 && a[1][3]== 1 && a[0][4] == 1 )
{
a[4][0] == 2;
a[3][1] == 2;
a[2][2] == 2;
a[1][3] == 2;
a[0][4] == 2;
return 1;
}
return 0;
}