PROGRAM TO PRINT LOWER TRIANGULAR MATRIX

/*PROGRAM TO PRINT LOWER TRIANGULAR MATRIX*/
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,i,j,a[10][10];
clrscr();
printf(“Enter the order of a square matrix: “);
scanf(“%d%d”,&m,&n);
if(m==n)
{
printf(“Enter %d elements in the matrix:\n”,m*n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
}
printf(“You have entered the following matrix:\n”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf(“%4d”,a[i][j]);
printf(“\n”);
}
printf(“Lower triangular matrix for the given matrix is:\n”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i<j)
a[i][j]=0;
printf(“%4d”,a[i][j]);
}
printf(“\n”);
}
}
else
printf(“Matrix should be a square matrix,So enter a valid order”);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *