/* * Author : Amit Dutta * Date : 12 Dec 2025 * Repo : https://github.com/notamitgamer/bsc * License : MIT License (See the LICENSE file for details) */ /* Write a program to find the upper and lower triangular matrix. */ /* Author: Amit Dutta, Date: 18-11-2025 */ #include int main() { int i, j, rows, cols; printf("\nEnter the number of rows and columns : "); scanf("%d %d", &rows, &cols); if (rows != cols) { printf("Triangular matrix definitions only apply to square matrices (rows == columns).\n"); return 1; } int matrix[rows][cols]; printf("Enter the elements of matrix (%d x %d): \n", rows, cols); for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) { printf("Position %d%d: ", i, j); scanf("%d", &matrix[i][j]); } printf("\nMatrix: \n"); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) printf("%d ", matrix[i][j]); printf("\n"); } printf("\nUpper triangular of the Matrix: \n"); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (j >= i) printf("%d ", matrix[i][j]); else printf("~ "); } printf("\n"); } printf("\nLower triangular of the Matrix: \n"); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (j <= i) printf("%d ", matrix[i][j]); else printf("~ "); } printf("\n"); } return 0; }