Upper or lower triangular matrix

Question:
To check whether the given matrix is an upper or lower triangular matrix or not a triangular matrix
Logic:
- Get the matrix as input from the user.
- If all the positions i>j are zero or elements below the diagonal are zero is an upper triangular matrix.
- If all the positions i<j are zero or elements above the diagonal are zero is a lower triangular matrix.
- If both conditions are satisfied or both not satisfy means then the matrix is not a triangular matrix.
Definition:
A square matrix A is said to be an Upper T Matrix if all entries below the main diagonal are zero (if i>j, aij=0) and called a Lower T Matrix if all entries above the main diagonal are zero (if i<j, aij=0).
Let A and B be square n×n triangular matrices. Then:
a) If A is an upper Triangle matrix, then AT is a lower Triangle matrix. If A is a lower Triangle matrix, then AT is an upper Triangle matrix.
b) If A and B are both upper Triangle matrices, then AB is an upper Triangle matrix. If A and B are both lower Triangle matrices, then AB is a lower Triangle matrix.
More about Triangular matrix>>
Program:
[code lang=”c”]
#include<stdio.h>
void main()
{
int a[10][10],i,j,l=0,k=0,n;
printf("enter the length:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j&&a[i][j]!=0) //checks for upper triangular matrix
{
l=1;
}
else if(i<j&&a[i][j]!=0) //checks for lower triangular matrix
{
k=1;
}
}
}
if(l==k) //both vales are equal means not a triangular matrix
{
printf("Not a triangular matrix");
}
else
{
if(l==0)
{
printf("Upper triangular matrix");
}
else
{
printf("Lower triangular matrix");
}
}
}
[/code]