C Program of lower and upper triangular matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int rows, cols, r, c, matrix[10][10];
clrscr();
printf("**Program to print lower and upper triangular matrix**\n");
printf("enter the number of rows for the matrix: ");
scanf("%d", &rows);
printf("\n");
printf("enter the number of columns for the matrix: ");
scanf("%d", &cols);
printf("\n");
printf("enter the elements for the Matrix: \n");
for(r = 0; r < rows; r++)
{
for(c = 0;c < cols;c++)
{
scanf("%d", &matrix[r][c]);
}
}
printf("\n The Lower Triangular Matrix is: ");
for(r = 0; r < rows; r++)
{
printf("\n");
for(c = 0; c < cols; c++)
{
if(r >= c)
{
printf("%d\t ", matrix[r][c]);
}
else
{
printf("0");
printf("\t");
}
}
}
printf("\n\n The Upper Triangular Matrix is: ");
for(r = 0; r < rows; r++)
{
printf("\n");
for(c = 0; c < cols; c++)
{
if(r > c)
{
printf("0");
printf("\t");
}
else
{
printf("%d\t ", matrix[r][c]);
}
}
}
getch();
}
0 Comments
Have any query? Want any type of module?
Please comment it down and let me know.