Q:

C Program to check whether it is lower triangular matrix or not

0

C Program to check whether it is lower triangular matrix or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#define MAX_ROWS 3
#define MAX_COLS 3

int main()
{
    int array[MAX_ROWS][MAX_COLS];
    int row, col, isLower;

   
    printf("Enter elements in matrix of size %dx%d: \n", MAX_ROWS, MAX_COLS);
    for(row=0; row<MAX_ROWS; row++)
    {
        for(col=0; col<MAX_COLS; col++)
        {
            scanf("%d", &array[row][col]);
        }
    }

   
    isLower = 1;
    for(row=0; row<MAX_ROWS; row++)
    {
        for(col=0; col<MAX_COLS; col++)
        {
           
            if(col>row && array[row][col]!=0)
            {
                isLower = 0;
            }
        }
    }

   
    if(isLower == 1)
    {
        printf("\nMatrix is Lower triangular matrix: \n");

        /* Print elements of lower triangular matrix */
        for(row=0; row<MAX_ROWS; row++)
        {
            for(col=0; col<MAX_COLS; col++)
            {
                printf("%d ", array[row][col]);
            }

            printf("\n");
        }
    }
    else
    {
        printf("\nMatrix is not a Lower triangular matrix");
    }

    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now