Saturday, 10 January 2015

C Program to display Lower Triangular Matrix



This is a C program which display the lower triangular form of a given matrix.

To display the lower triangular form of a given matrix we make all the elements above the diagonal row as zero.



PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,columns,i,j;
    printf("Enter order of matrix : \t");
    scanf("%d%d",&rows,&columns);
    int matrix[rows][columns];
    printf("\n\nEnter elements of a matrix\n");
    for(i=0;i<rows;i++)
    {
        for(j=0;j<columns;j++)
        {
            printf("Enter element m%d%d: \t",i+1,j+1);
            scanf("%d",&matrix[i][j]);
        }
    }
    printf("\n\nMATRIX is :\n");
    for(i=0;i<rows;i++)
    {
        for(j=0;j<columns;j++)
        {
            printf("%d\t",matrix[i][j]);
        }
        printf("\n");
    }
    printf("\n\nIts Lower Triangular form is: \n");
    for(i=0;i<rows;i++)
    {
        for(j=0;j<columns;j++)
        {
            if(i>=j)
            printf("%d\t",matrix[i][j]);
            else
                printf("%d\t",0);
        }
        printf("\n");
    }
    return 0;
}

OUTPUT :
C - Lower Triangular Matrix