Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Explanation / Answer

please rate - thanks #include #include #define SIZE 3 void doall(int [][SIZE]); int check ( int a[][SIZE] ); void print(int [][SIZE]); int main() {int a[SIZE][SIZE]={1,1,1,1,1,3,3,1,1}; //row all 1 int b[SIZE][SIZE]={1,1,2,1,1,3,1,2,1};   //col all 1 int c[SIZE][SIZE]={1,2,1,1,1,3,3,1,1};   //diagnol all1 int d[SIZE][SIZE]={2,2,1,1,1,3,1,3,1};   //other diagnolall 1 doall(a); doall(b); doall(c); doall(d); getch(); return 0;   } void doall(int array[][SIZE]) {printf("before "); print(array); check(array); printf("after "); print(array); } void print(int a[][SIZE]) {int i,j; for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote