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

Matrix Problem: For this problem, you are going to implement three functions cal

ID: 3687525 • Letter: M

Question

Matrix Problem: For this problem, you are going to implement three functions called isDiagonal, isUpperTriangular and isLowerTriangular which determine whether the matrix (passed to the function as a parameter) is diagonal, upper- triangular and/or lower-triangular. The matrix is diagonal, if all the cells other than [i][i] are zero (in other words cell[i][j] = 0 if i != j). The matrix is upper triangular if all the cells [i][j] is 0, if i > j. The matrix is lower triangular, if all the cells [i][j] is 0 if i < j.

? Function headers must be:
o isUpperTriangular(intmatrix[][MAX_SIZE],intsize);

o isLowerTriangular(intmatrix[][MAX_SIZE],intsize);

o isDiagonal(intmatrix[][MAX_SIZE],intsize);

? [Assumption] The matrix passed to these function are square matrix (i.e., number of rows of the matrix = number of columns of the matrix).
? [Assumption] The maximum size of the matrices is 20 by 20 (as MAX_SIZE is defined 20 by 20 in the program).

Explanation / Answer

Please find the below method implementation

A)

int isUpperTriangular(int matrix[][MAX_SIZE],int size)
{
   int flag =1;

   for(int i=0;i<size;i++)// Loop For Rows
   {
       for(int j=0;j<size;j++)// Loop For Columns
       {
           if(j<i && matrix[i][j]!=0)//Condition Check
           {
               flag=0;// Setting Flag =0 when not Upper
           }
       }
   }
   return flag;
}

B)

int isLowerTriangular(int matrix[][MAX_SIZE],int size)
{
   int flag=1;

   for(int i=0;i<size;i++)//Loop for Rows
   {
       for (int j=0;j<size;j++)// Loop for Columns
       {
           if(j>i && matrix[i][j]!=0)//Condition Check
           {
               flag=0;// Setting Flag =0 when not Lower
           }
       }
   }

   return flag;
}

c)

int isDiagonal(int matrix[][MAX_SIZE],int size)
{
   int flag=1;

   for(int i=0;i<size;i++)// Loop for Rows
   {
       for (int j=0;j<size;j++)//Loop for Columns
       {
           if(i!=j && matrix[i][j]!=0)// Condition Check
           {
               flag=0; // Setting Flag =0 when not Diagonal
           }
       }
   }

   return flag;
}