Lower triangular matrix in C
In this post, you will learn how to find the lower triangular matrix of a given matrix using the C programming language.
A square matrix whose elements above the main diagonal are zero is called a lower triangular matrix.
An n × n square matrix M = [aij] is said to be a lower triangular matrix if and only if aij = 0, for all i < j. This implies that all elements above the main diagonal of a square matrix are zero in a lower triangular matrix.
A general notation of a lower triangular matrix is L = [lij for i ≥ j, 0 for i < j].
An example of a lower triangular matrix is given below-
[11, 0, 0]
[13, 20, 0]
[11, 12, 3]
Algorithm for lower triangle matrix
int lower_mat(int mat[n][m])
START
STEP 1: DECLARE I AND j
STEP 2 : LOOP FOR i = 0 AND i < n AND i++
LOOP FOR j = 0 AND j < m AND j++
IF i < j THEN,
PRINT "0\t"
ELSE
PRINT mat[i][j]
END IF
END FOR
PRINT newline
END FOR
STOP
C Program to find lower triangle matrix
The given C program prints the lower triangle matrix.
#include <stdio.h>
#define n 3
#define m 3
int lower_matrix(int mat[n][m]){
int i, j;
for ( i = 0; i < n; i++){
for ( j = 0; j < m; j++){
if( i < j )
printf("0\t");
else
printf("%d\t", mat[i][j]);
}
printf("\n");
}
}
int main(int argc, char const *argv[]){
int mat[n][m] = {
{12, 21, 7},
{82, 13, 9},
{22, 43, 11}
};
lower_matrix(mat);
return 0;
}
Output of the above code:
12 0 0
82 13 0
22 43 11
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative