Upper or lower triangular matrix

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>jaij=0) and called a Lower T Matrix if all entries above the main diagonal are zero (if i<jaij=0).

Screen%20Shot%202014-06-08%20at%2012.52.45%20PM.png

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:


#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");
        }
    }
}

You might also like:

Program to perform string operations | ZOHO

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x